<html>
<body>
<script>
function BMI(form)
{
var bmi;
Height = parseFloat(form.height.value)/100;
Weight = parseFloat(form.weight.value);
bmi = Weight/Math.pow(Height,2);
form.index.value = bmi.toFixed(2).toString();
if(bmi<18.5)
form.result.value = "體重過輕";
else if(18.5<=bmi && bmi<24)
form.result.value = "正常範圍";
else if(24<=bmi && bmi<=27)
form.result.value = "體重過胖";
else
form.result.value = "肥胖";
}
</script>
<form name="MyBmi">
身高:<input type="text" name="height"><br>
體重:<input type="text" name="weight"><br>
<input type="button" onclick="BMI(MyBmi)" value="確定">
<br>
<br>
BMI指數:<input type="text" name="index"><br>
<textarea name="result"></textarea>
</form>
</body>
</html>