-
Notifications
You must be signed in to change notification settings - Fork 0
/
BMI-Calculator.html
202 lines (152 loc) · 4.87 KB
/
BMI-Calculator.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
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<title>Calculadora IMC</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<div class="jumbotron text-center">
<h1>Calculadora IMC</h1>
<p class="lead">
<form id="div01" name="calculate">
<fieldset>
<label>
Altura (m)
<br/>
<input id="height" type="text" name="Altura" class="form-control">
</label>
<br /><br />
<label class="control-label">
Peso (kg)
<br/>
<input id="weight" type="text" name="Peso" class="form-control">
</label>
<br /><br />
<button type="button" onclick="Function1()" class="btn btn-default">Calcular</button>
<button type="button" onclick="resetForm()" class="btn btn-default">Limpar</button>
</fieldset>
</form>
</p>
<div id="div02">
<table class="table table-striped table-bordered">
<thead>
<tr>
<th class="text-center">IMC</th>
<th class="text-center">Situação</th>
</tr>
</thead>
<tbody>
<tr>
<td> <span id="Result"></span> </td>
<td> <span id="bmi"></span> </td>
</tr>
</tbody>
</table>
<span class="navbar-left"><button type="button" onclick="Function2()" class="btn btn-default">Voltar</button></span>
<br><br>
</div>
<script type="text/javascript">
var display2 = document.getElementById('div02').style.display = 'none';
function Function1()
{
x = document.calculate;
if (x.height.value == "")
{
alert("O campo " + x.height.name + " deve ser preenchido.");
x.height.focus();
return false;
}
if (isNaN(x.height.value.replace(',','.')))
{
alert("O campo " + x.height.name + " deve conter apenas numeros.");
x.height.focus();
return false;
}
if (x.weight.value == "")
{
alert("O campo " + x.weight.name + " deve ser preenchido.");
x.weight.focus();
return false;
}
if (isNaN(x.weight.value.replace(',','.')))
{
alert("O campo " + x.weight.name + " deve conter apenas numeros.");
x.weight.focus();
return false;
}
var display = document.getElementById('div01').style.display;
if(display == "none")
document.getElementById('div01').style.display = 'block';
else
document.getElementById('div01').style.display = 'none';
if(display2 == "none")
document.getElementById('div02').style.display = 'block';
else
document.getElementById('div02').style.display = 'none';
var height = document.getElementById("height").value.replace(',','.');
var weight = document.getElementById("weight").value.replace(',','.');
var y1 = parseFloat(height) * parseFloat(height);
var y2 = parseFloat(weight) / y1;
var Result = y2;
var bmi;
if (Result < 17)
{
bmi = "Muito abaixo do peso";
}
else if (Result >= 17 && Result <= 18.49)
{
bmi = "Abaixo do peso";
}
else if (Result >= 18.5 && Result <= 24.99)
{
bmi = "Peso normal";
}
else if (Result >= 25 && Result <= 29.99)
{
bmi = "Acima do peso";
}
else if (Result >= 30 && Result <= 34.99)
{
bmi = "Obesidade I";
}
else if (Result >= 35 && Result <= 39.99)
{
bmi = "Obesidade II (severa)";
}
else if (Result >= 40)
{
bmi = "Obesidade III (mórbida)";
}
Result = parseInt(Result);
document.getElementById("bmi").innerHTML = bmi;
document.getElementById("Result").innerHTML = Result;
}
function Function2()
{
var display = document.getElementById('div01').style.display;
if(display == "none")
document.getElementById('div01').style.display = 'block';
else
document.getElementById('div01').style.display = 'none';
if(display2 == "none")
document.getElementById('div02').style.display = 'none';
else
document.getElementById('div02').style.display = 'block';
}
function resetForm()
{
document.getElementById("div01").reset();
}
</script>
</div>
</div> <!-- /container -->
</body>
</html>