-
Notifications
You must be signed in to change notification settings - Fork 10
/
bmi.html
209 lines (178 loc) · 5.38 KB
/
bmi.html
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<!DOCTYPE html>
<html>
<head>
<style>
/* The Modal (background) */
.modal
{
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
padding-top: 100px; /* Location of the box */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
background-color: #313131;
opacity: 0.95;
}
/* Modal Content */
.modal-content
{
background-color: #fefefe;
margin: auto;
padding: 20px;
border: 1px solid #888;
width:20%;
overflow:auto;
border-radius:12px;
text-align:center;
font-family: raleway;
font-size:18px;
}
/* The Close Button */
.close {
color: #aaaaaa;
float:right;
top:0px;
font-size: 28px;
font-weight: bold;
font-family: Arial, Helvetica, sans-serif;
font-weight:100;
}
.close:hover,
.close:focus {
color: #000;
text-decoration: none;
cursor: pointer;
}
</style>
</head>
<body>
<h2>Modal Example</h2>
<!-- Trigger/Open The Modal -->
<p id="myBtn">Open Modal</p>
<!-- The Modal -->
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close">x</span><br>
Age:<br>
<input type="text" name="age" id="age1" placeholder="Your age" onblur="age_validate()" onfocus="validate_age()" required><br><p id="p1"></p>
Gender:<br>
<input type="radio" name="gender" id="gen1" value="Male" >Male
<input type="radio" name="gender" id="gen2" value="Female" >Female<br><p id="p2"></p>
Height:<br>
<input type="text" name="height" id="hei1" placeholder="centimeters" onfocus="validate_height()" onblur="height_validate()"><br><p id="p3"></p>
Weight:<br>
<input type="text" name="weight" id="wei1" placeholder="Kilogram" onfocus="validate_weight()" onblur="weight_validate()"><br><p id="p4"></p>
<input type="submit" value="Calculate" onclick="return evalute()">
<p>
<span id="output"></span><br>
<span id="comment"></span>
</p>
</div>
</div>
<script>
// Get the modal
var modal = document.getElementById('myModal');
// Get the button that opens the modal
var btn = document.getElementById("myBtn");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks the button, open the modal
btn.onclick = function() {
modal.style.display = "block";
document.getElementById("age1").value = "";
document.getElementById("hei1").value = "";
document.getElementById("wei1").value = "";
document.getElementById("gen1").checked = false;
document.getElementById("gen2").checked = false;
document.getElementById("p1").innerHTML = "";
document.getElementById("p2").innerHTML = "";
document.getElementById("p3").innerHTML = "";
document.getElementById("p4").innerHTML = "";
document.getElementById("output").innerHTML = "";
document.getElementById("comment").innerHTML = "";
}
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
function evalute()
{
var m=document.getElementById("gen1");
var f=document.getElementById("gen2");
if (m.checked == false && f.checked == false)
{
document.getElementById("p2").innerHTML="Plz.. select gender";
return false;
}
var h=document.getElementById("hei1").value;
var w=document.getElementById("wei1").value;
h=h/100;
var bmi=(w*1)/(h*h);
bmi=parseInt(bmi);
var output = bmi.toPrecision(4);
document.getElementById("output").innerText=(bmi);
if (output < 18.5){
document.getElementById("comment").style='color:#21618C;';
document.getElementById("comment").innerText = "This means you are Underweight";
}
else if (output >= 18.5 && output <= 25){
document.getElementById("comment").style='color:#52BE80;';
document.getElementById("comment").innerText = "This means you are Normal";
}
else if (output >= 25 && output <= 30) {
document.getElementById("comment").style='color:#E59866;';
document.getElementById("comment").innerText = "This means you are Obese";
}
else if (output > 30){
document.getElementById("comment").style='color:#D35400;';
document.getElementById("comment").innerText = "This means you are Overweight";
}
return true;
}
function age_validate(){
var a=document.getElementById("age1");
if (a.value==""){
document.getElementById("p1").innerHTML="Plz.. fill age";
}
}
//function gen_validate(){}
function height_validate(){
var h=document.getElementById("hei1").value;
if (h==""){
document.getElementById("p3").innerText="Plz.. fill height";
}
}
function weight_validate(){
var w=document.getElementById("wei1").value;
if (w==""){
document.getElementById("p4").innerText="Plz.. fill weight";
}
}
function validate_age(){
document.getElementById('p1').innerHTML="";
//document.getElementById('age1').style='none';
}
function validate_height(){
document.getElementById('p3').innerHTML="";
//document.getElementById('hei1').style='none';
}
function validate_weight(){
document.getElementById('p4').innerHTML="";
//document.getElementById('wei1').style='none';
}
</script>
</body>
</html>