-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalc.php
74 lines (63 loc) · 1.69 KB
/
calc.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
<!DOCTYPE html>
<html>
<head>
<title>Tip Calculator</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style>
.middle {
width: 500px;
height: 200px;
top:0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}
</style>
<script
src="https://code.jquery.com/jquery-3.1.1.min.js"
integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
crossorigin="anonymous">
</script>
<script>
function send_post_request()
{
var bill = $("#bill").val();
var tippercent = $("input[name='tippercent']:checked").val();
var dataString = 'bill=' + bill + '&tippercent=' + tippercent;
$.ajax({
type:"post",
url:"calculate.php",
data:dataString,
cache:false,
success:function(data) {
$("#result").html(data);
}
});
return false;
}
</script>
</head>
<body>
<form class="middle">
<h1 >Tip Calculator</h1>
Bill Amount: $<input type="text" id="bill">
<br /> <br />
Tip Percentage:
<?php
$radio_array_values = array(10, 15, 20);
$radio_array_labels = array("10%", "15%", "20%");
// show radio buttons using php loop
for($counter=0; $counter <3; $counter++)
{
echo("<input type=\"radio\" name=\"tippercent\" value=\"$radio_array_values[$counter]\" id=\"radio$counter\"> $radio_array_labels[$counter]");
}
echo "<script> document.getElementById(\"radio2\").setAttribute(\"checked\", \"checked\");</script>";
?>
<br /> <br />
<input type="submit" value="calculate!" onclick="return send_post_request();">
</form>
<div id="result" class="middle">
</div>
</body>
</html>