-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
80 lines (78 loc) · 2.19 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
require 'UnitConverter.php';
$convert = new UnitConverter();
$units = json_decode($convert->getUnit());
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Unit Converter</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<nav class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="#">Unit Converter</a>
</div>
</div>
</nav>
<div class="container">
<div class="row">
<div class="col-sm-3"></div>
<div class="col-sm-6">
<div class="form-group">
<label for="number">Enter your number:</label>
<input type="text" class="form-control" id="number" name="number">
</div>
<div class="form-group">
<label for="from">From:</label>
<select class="form-control" id="from">
<?php foreach($units as $unit => $unit_data){?>
<option value="<?php echo $unit;?>"><?php echo $unit_data->name;?></option>
<?php }?>
</select>
</div>
<div class="form-group">
<label for="to">To:</label>
<select class="form-control" id="to">
<?php foreach($units as $unit => $unit_data){?>
<option value="<?php echo $unit;?>"><?php echo $unit_data->name;?></option>
<?php }?>
</select>
</div>
<button class="btn btn-primary" id="submit">Convert</button>
<hr>
<div class="panel panel-default">
<div class="panel-body" id="output"></div>
</div>
</div>
<div class="col-sm-3"></div>
</div>
</div>
</body>
</html>
<script>
$("#submit").click(function(){
var number=$("#number").val();
var from=$("#from").val();
var to=$("#to").val();
$.post("api.php",
{
number:number,
from:from,
to:to
},function(data){
$("#output").html(data);
});
});
$('#number').keypress(function(e){
if(e.which == 13){
$('#submit').click();
}
});
</script>