Body Mass Index (BMI) Calculator

Introduction | Demonstration Calculator | Source Code

How The Body Mass Index (BMI) Calculator Works

Body Mass Index (BMI) is a general indicator of whether or not you are maintaining a healthy weight based on the ratio of your weight to your height. It’s an imperfect scale as it doesn’t account for differences in body types. For example, a 5 foot 9 inch bodybuilder who weighs 215 pounds and has a 6% body fat would be labeled obese. And there is already a new scale just for people from Southeast Asia where the ranges are lowered.

While it can be a good indicator of the healthiness of your weight if you fall within certain statistical norms that were used to develop it, it should be taken with a significant grain of salt and should not be used as a substitute for a professional evaluation of your health by a doctor.

Introduction | Demonstration Calculator | Source Code

Demonstration Calculator


Weight:

Height:

Your BMI is:

Introduction | Demonstration Calculator | Source Code

Body Mass Index (BMI) Calculator Source Code

This calculator is licensed to you under Creative Commons Attribution 3.0. If you would like to use the source code on your site or create a derivative work from it, you must include the following HTML on the page where the calculator appears. We’re giving you this code for free with a legal license to use it. All you have to do is credit us in the manner we specify.

Required Credit HTML

INSTALLATION

Just cut and paste the Javascript code and HTML form below into your page. If you want to customize the appearance of the form, feel free. Just make sure the input name and form id/name values are not changed.

<script type="text/javascript">

function calcBMI(){

// Get Variables and validate to make sure they're numbers, 
// setting them to a value of 1 if they're not.

var weight = (isNaN(document.wcbubba.weight.value)) ? 1 : document.wcbubba.weight.value;

if (weight == 0) alert("Results will be inaccurate.  Weight is not a valid number.");

var height = (isNaN(document.wcbubba.height.value)) ? 1 : document.wcbubba.height.value;

if (height == 0) alert("Results will be inaccurate.  Height is not a valid number.");

// set multipliers based on whether metric or English units were selected

var wmult = (document.wcbubba.units.value == "pounds") ? 2.204 : 1;

// Turns inches/centimeters into meters

var hmult = (document.wcbubba.hunits.value == "inches") ? .0254 : .01;

// Do the calculation (weight in kg divided by the height in meters 
// times itself). The multiplication by 10 and then division by ten
// work in conjunction with Math.round() to round the value to one
// decimal place of precision.

var BMI = Math.round(((weight / wmult)/((height * hmult)*(height * hmult))) *10)/10;

// get the analysis - note this is for general purpose, there is a separate scale for
// Southeast Asian people and there may be more variants on the way

var result = "";
if(BMI < 16.5) result = "severely underweight";
else if((BMI >=16.5)&&(BMI<=18.49)) result = "underweight";
else if((BMI >=18.5)&&(BMI<=25)) result = "normal";
else if((BMI >=25.01)&&(BMI<=30)) result = "overweight";
else if((BMI >=30.01)&&(BMI<=35)) result = "obese";
else if((BMI >=35.01)&&(BMI<=40)) result = "clinically obese";
else result = "morbidly obese";

document.getElementById('results').innerHTML = "Your Body Mass Index (BMI) is: " + BMI + ".<br><br>This would be considered " + result + ".";

}
</script>

<form name="wcbubba" id="wcbubba" action="javascript:void()">
Weight:<br> <input type=text name="weight" size="6"> <select name="units"><option value="pounds">pounds<option value="kilos">kg</select><br><br>

Height:<br> <input type=text name="height" size="6"> <select name="hunits"><option value="inches">inches<option value="cm">cm</select><br><br>

<input type="submit" value="Calculate My BMI" onClick="calcBMI();"></form><br>

<div id="results" style="border:1px solid #000;padding:4px;font-size:15px;font-weight:bold;width:400px;">
Your BMI is:<br><br>
</div>

Leave a Reply