The formula for calculating body mass index is weight * 703 / height².
Create a web page that contains three text boxes: weight in pounds, height in inches, and one that will contain the BMI result. Create a script with a function named calcBMI() that performs the calculation using the values in the weight and height text boxes and assign the result of the BMI text box. Convert the result to an integer by using the parseInt() function. Reference the text boxex from within the function by using the document object, form name, and name and value attributes of each text box (don’t use function arguments). Perform the calculation by calling the function from onclick event in a button element.
This what I could come up with:
<html><head>
<title>...</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<script type="text/javascript">
/*<CDATA[[*/
function calcBMI(){
var weight, height, total;
document.form.height.value = weight * 703;
document.form.weight.value = (height * height);
var total = weight / height;
document.form.result.value = total;
}
/*]]>*/
</script>
</head>
<body>
<form name="form">
Weight: <input type="text" name="weight" /><br />
Height: <input type="text" name="height" /><br />
Result: <input type="text" name="result" /><br />
<input type="button" value="BMI Result!" onclick="calcBMI()" />
</form>
Generally the problem you are facing is you are trying to assign values to the text boxes when you should be trying to take the values of the text boxes. Change your code to: