Use this script for a BMI calculator (Body Mass Index). Measurements are computed using the metric system. A perfect addition for a health Web site.
- Copy the coding into the HEAD of your HTML document
- Add the last code into the BODY of your HTML document
<!– STEP ONE: Paste this code into the HEAD of your HTML document –>
<HEAD>
<script type=”text/javascript”>
<!– This script and many more are available free online at –>
<!– The JavaScript Source!! http://javascriptsource.com –>
<!– Created by: Bob Mason :: http://www.omega-cottage.co.uk/WLS –>
<!– Begin
function calculateBMI() {
var weight = eval(document.form.weight.value)
var height = eval(document.form.height.value)
var height2 = height / 100
var BMI = weight / (height2 * height2)
document.form.BodyMassIndex.value=custRound(BMI,1);
}
function custRound(x,places) {
return (Math.round(x*Math.pow(10,places)))/Math.pow(10,places)
}
// End –>
</script>
</HEAD>
<!– STEP TWO: Copy this code into the BODY of your HTML document –>
<BODY>
<div align=”center”>
<form name=”form” id=”form”>
<input type=”Text” name=”weight” size=”4″> Weight (in Kilos)
<input type=”Text” name=”height” size=”4″> Height (in Centimeters)<br><br>
<input type=”Text” name=”BodyMassIndex” id=”BodyMassIndex” size=”4″> BMI
<input type=”button” style=”font-size: 8pt” value=”Calculate” onClick=”calculateBMI()” name=”button”>
<input type=”reset” style=”font-size: 8pt” value=”Clear Form”>
</form>
</div>
<p><center>
<font face=”arial, helvetica” size”-2″>Free JavaScripts provided<br>
by <a href=”https://javascriptsource.com”>The JavaScript Source</a></font>
</center><p>