Click to See Complete Forum and Search --> : BMI Calculator


WeightResolve
03-19-2005, 04:54 PM
Hello everyone. I have been trying to use a simple javascript on my site a BMI calculator. Cant make this one work period. I understand HTML pretty well but am new to javascript. Most javascript runs without trouble on my site... Can anyone help?
This is the one I have been messing with for to many hours already:

<!-- TWO STEPS TO INSTALL BODY MASS INDEX:

1. Copy the coding into the HEAD of your HTML document
2. 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 LANGUAGE="JavaScript">

<!-- Original: Marat Rikelman (rikelman@bellsouth.net) -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function mod(div,base) {
return Math.round(div - (Math.floor(div/base)*base));
}
function calcBmi() {
var w = document.bmi.weight.value * 1;
var HeightFeetInt = document.bmi.htf.value * 1;
var HeightInchesInt = document.bmi.hti.value * 1;
HeightFeetConvert = HeightFeetInt * 12;
h = HeightFeetConvert + HeightInchesInt;
displaybmi = (Math.round((w * 703) / (h * h)));
var rvalue = true;
if ( (w <= 35) || (w >= 500) || (h <= 48) || (h >= 120) ) {
alert ("Invalid data. Please check and re-enter!");
rvalue = false;
}
if (rvalue) {
if (HeightInchesInt > 11) {
reminderinches = mod(HeightInchesInt,12);
document.bmi.hti.value = reminderinches;
document.bmi.htf.value = HeightFeetInt +
((HeightInchesInt - reminderinches)/12);
document.bmi.answer.value = displaybmi;
}
if (displaybmi <19)
document.bmi.comment.value = "Underweight";
if (displaybmi >=19 && displaybmi <=25)
document.bmi.comment.value = "Desirable";
if (displaybmi >=26 && displaybmi <=29)
document.bmi.comment.value = "prone to health risks";
if (displaybmi >=30 && displaybmi <=40)
document.bmi.comment.value = "Obese";
if (displaybmi >40)
document.bmi.comment.value = "Extremely obese";
document.bmi.answer.value = displaybmi; }
return rvalue;
}
// End -->

</script>
</HEAD>

<!-- STEP TWO: Copy this code into the BODY of your HTML document -->

<BODY>

<form name=bmi>
<center>
<table width=200 border=0>
<tr>
<td align=center><B>Weight:</B>
<input type=text name=weight SIZE=3 maxlength=3> lbs.</td>
</tr>
<tr>
<td align=center><B>Height:</B>
<input type=text name=htf size=1 maxlength=1> Ft.
<input type=text name=hti size=2 maxlength=2> In.
</td>
</tr>
<tr>
<td align=center>
<input type=button value="Calculate BMI" onclick="calcBmi()">

<hr></td>
</tr>
<tr>
<td><B>Body Mass Index</B>
<input type=text name=answer size=3>
</td>
</tr>
<tr>
<td>
According to the Panel on Energy, Obesity, and
Body Weight Standards published by American
Journal of Clinical Nutrition, your category is:<br>
<input type=text name=comment size=25>
</td>
</tr>
</table>
</center>
</form>

<p><center>
<font face="arial, helvetica" size="-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>

<!-- Script Size: 2.56 KB -->

Khalid Ali
03-19-2005, 06:46 PM
first of all u need to post your question in correct forums to get a correct answer.(which is JavaScript not Java)