I am trying to get the document.bmi.answer.value to equal to ans. But it is not showing up. Does anyone see any errors in my code?
This is in my head:
<script type="text/javascript">
function calcbmi()
{
var hh = parseFloat(document.getElementByName('height').value);
var ww = parseFloat(document.getElementByName('weight').value);
var ans = (( ww / ( hh * hh ))*703);
document.getElementByName('answer').value = ans;
}
</script>
This is in my body:
<form name="bmi">
<p> Height <input type="text" name="height"></p>
<p> Weight <input type="text" name="weight"></p>
<p> BMI <input type="text" name="answer" value=""></p>
<input type="button" value="Calculate" onclick="calcbmi();">
</form>
Thanks for the help!
Here is my whole code as my error my not reside in the javascript or form. I cant for the life of me see it though..
<!DOCTYPE HTML>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function calcbmi()
{
var hh = parseFloat(document.getElementByName('height').value);
var ww = parseFloat(document.getElementByName('weight').value);
var ans = (( ww / ( hh * hh ))*703);
document.getElementByName('answer').value = ans;
}
</script>
</head>
<body>
<h1>Body Mass Index</h1>
<form name="bmi">
<p> Height <input type="text" name="height"></p>
<p> Weight <input type="text" name="weight"></p>
<p> BMI <input type="text" name="answer" value=""></p>
<input type="button" value="Calculate" onclick="calcbmi();">
</form>
</body>
</html>
)at the end ofvar ans = ( ww / ( hh * hh ))*703);