BMI calculator script

Height:
Weight:
 

JavaScript code for BMI calculator

Add the following lines of code between <head> and </head> tags of your web page.

Code | Download
<script type="text/javascript">
<!--
function bmi()
{
    var w = parseFloat(document.frm.txtWeight.value);
    var h = parseInt(document.frm.txtHeight.value);
    var errors='';
    if (document.frm.opHeight.value == "Inch") {h = h * 2.54;}
	if (document.frm.opWeight.value == "Lb") {w = w * 0.4536;}
	if ((w < 20)||(w > 200)||isNaN(w)){errors+='Enter correct weight.\n';}
    if ((h < 100) || (h > 250)||isNaN(h)){errors+='Enter correct height.\n';}
    if (errors){
    alert('The following error(s) occurred:\n'+errors);
    return 0;}
    document.getElementById('feedback').innerHTML = 'Your BMI is ' + Math.round(10*((w * 10000 / (h * h))))/10;
}
function resetAll(){
document.getElementById('feedback').innerHTML="";
return true;
}
-->
</script>

Add the following lines of code between <body> and </body> tags where you want to display the BMI calculator.

Code | Download
<form name="frm" id="cal_frm" style="width:300px; margin:10px 10px 20px 10px;" onsubmit="return false">
<table id="cal_data">
<tr>
<td style="padding-left:5px;">Height:</td>
<td><input class="cal_text" type="text" name="txtHeight" ></td>
<td><select class="cal_option" name="opHeight">
<option value="Cm">Cm</option>
<option value="Inch">Inch</option>
</select></td>
</tr>
<tr>
<td style="padding-left:5px;">Weight:</td>
<td><input class="cal_text" type="text" name="txtWeight" ></td>
<td><select class="cal_option" name="opWeight">
<option value="Kg">Kg</option>
<option value="Lb">Pound</option>
</select></td>
</tr>
<tr>
<td colspan="3" id="feedback" style="padding:10px 0 20px 0; border:none; font-weight:600; color:#555555; font-family:tahoma;"></td></tr>
<tr>
<td colspan="2" style="border:none; padding-bottom:10px;">
<input onclick="bmi()" class="cal_button" type="button" value="Calculate" >&nbsp;<input onclick="resetAll()" type="reset" value="Reset" class="cal_button" ></td></tr>
</table></form>

What is BMI

BMI stands for Body Mass Index. It is a number calculated for a person's weight and height. This data is extensively used by the health personalities to measure and compare the body fat of a person. BMI is not a direct measure of body fat. But as statistics are available for normal health people, BMI is good substitution of direct body fat measurement and gives fairly good result for most of the people.

BMI for adult:

BMI Weight Status
Below 18.5 Underweight
18.5 to 24.9 Normal
25 to 29.9 Overweight
30.0 or above Obese

Advantages and limitations of BMI:

The main advantages of BMI as a body fat indicator are:-
  • BMI is very easy to measure. Only two parameters, height and weight are required which can be easily measured by common people.
  • As it is accepted as a general standard for measuring body fat, a person can compare his health with others.
The limitations of BMI are:-
  • BMI can't discriminate between body fat and muscle. So a body builder may find himself as obese in BMI scale.
  • Age and sex are not considered in BMI measurement. So analysis of BMI varies with those parameters.

Though no online method can give you accurate measurement of your body fat, the waist circumference method developed by US Navy gives you much better prediction. Please use our Calorie counter to know your percentage of body fat. It also gives you, your everyday calorie need.

User comments:

Add comment

RAMUI WEBBLOG
HomeAboutContact SitemapTerms of useXMLForum
© 2010,  http://ramui.com   All rights reserved.
Powered by: ramui webblog® Version 1.0