Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: bmi calculator with javascript

1. ## bmi calculator with javascript

I need help trying to figure out how to get my bmi calculator to work. I cant figure out what is wrong with my formula part and why it wont calculate the numbers you type in...pls help!

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>

<script type="text/javascript">

function calculateBMI()
{
var weight = numb(document.data.weight.value)
var height = numb(document.data.height.value)
var height2 = height2 * height2
var BMI = weight * 703 / (height2 * height2)

document.form.BodyMassIndex.value=custRound(BMI,1);
}

</script>
<title></title>

<style type="text/css">
div.c2 {text-align: center}
input.c1 {font-size: 8pt}
</style>
</head>
<body>
<div class="c2">
<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" class="c1" value="Calculate" onclick="calculateBMI()" name="button"> <input type="reset" class="c1" value="Clear Form"></form>
</div>
</body>
</html>

• Question 1: Where did you get that formula from? BMI usually is (weight in kg)/(height in cm)^2 and you are (trying) to calculate (weight in kg) * 703 / (height in cm)^4

Question 2: You are using a function numb() which is defined nowhere. Where did you get it from? Usually the native Javascript function for that purpose is called Number()

Question 3: What is document.data? I only see document.form in your HTML

Something like that will calculate the BMI (if weight and height are given correctly)
Code:
```function calculateBMI()
{
var weight = Number(document.form.weight.value);
var height = Number(document.form.height.value);
var BMI = weight  / (height * height);

document.form.BodyMassIndex.value=BMI.toFixed(1);
}```

•

#### LinkBacks (?)

1. ###### JavaScript - Javascript Calculator Input Box - AllWebDevHelp.com
Refback This thread
06-12-2014, 04:38 AM
2. ###### JavaScript - Bmi Calculator With Javascript - AllWebDevHelp.com
Refback This thread
03-25-2014, 05:59 AM

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•