I would like to know how I can calculate the BMI, but first check if the textfield has been filled.
And how to format height mask to auto fill (X.XX)?
<html>
<meta charset="utf-8">
<head>
<center>
<title>testando JS</title>
<font face = "Corbel">
<body>
<br>
<img width= "200px" height="100px" align="center" src="imagem/IMC_full.png"/>
<br>
<br>
<form>
Digite seu peso (Kg)<br>
<input type="text" name="peso" id="peso" value="xx" maxlength="3" size="10" style="text-align:center"><br><br>
Digite sua altura (m)<br>
<input type="text" name="altura" id="altura" value="x.xx" maxlength="4" size="10" style="text-align:center"><br><br>
<input type="submit" value="Calcular IMC" onclick="calculaIMC(),teste()">
<br>
<br>
<br>
<br>
<img width="800px" height="250px" align="center" src="imagem/tabela-imc.jpg" />
</form>
<script type="text/javascript">
function calculaIMC(){
var peso = document.getElementById("peso").value;
var altura = document.getElementById("altura").value;
var imc = Math.round(peso /(altura*altura));
alert("Seu IMC é "+imc);
}
function teste(){
if (peso ==""){
alert("Prencha peso");
document.peso.focus();
return false;
}
if (altura ==""){
alert("Preencha altura");
document.altura.focus();
return false;
}
}
</script>
</center>
</head>
</body>
</html>