JavaScript BMI Calculator


Time for some learnin' & JavaScriptin'

One thing I had to do for a client a while back was create a JavaScript body mass index calculator.

She just wanted 2 fields:

  • Height (inches)
  • Weight (pounds)

On that same page she also had a table displaying the translation of BMI calculations from the CDC Website.

BMI Weight Status
Below 18.5 Underweight
18.5 – 24.9 Normal
25.0 – 29.9 Overweight
30.0 and Above Obese

So being me, I decided this would be way cooler if not only did it spout out your BMI, but if it also highlited the proper category for you. Cool? Maybe not so much so, but it's neat enough!

Let's start out with...

The Form

The form is simple enough. Two fields with a button within the <form> named bmi

<form name="bmi">
    <label for="height">Height(in):<br/>
    <input type="text" name="height" id="height" value="" /></label><br />
    <label for="weight">Weight (lb):<br/>
    <input type="text" name="weight" id="weight" value="" /></label><br />
    <input type="button" value="Calculate" id="calc" name="calc" />
</form>

Boring, I know, we'll jazz it up with styles later. Promise. Oh and don't forget to put the <p> with an id of 'BMIoutput' on your page too. This is where your calculated BMI will go.

<p id="BMIoutput"></p>

Demo: Step 1

Continue on to page 2: Adding the JavaScript to make it work

Information and Links

Join the fray by commenting, tracking what others have to say, or linking to it from your blog.


61 subscribers couldn't be wrong*!
Subscribe to the Ninedays Blog feed!
* Not statistically proven, they could be wrong.
Similar Entries
Quick and Dirty JavaScript Pop-Up Windows
Our topic today: JavaScript pop-up windows. I have a quick and dirty method I usually use to create JavaScript pop-up windows. I use it because it allows the user to still access the page if they have JavaScript turned off and it centers the window on the screen. The function accepts 3 parameters the URL, window
Alternating Colors Using Prototype
Using the CSS nth-child selectors I've learned how to alternate colors using the Prototype library. Great to apply a style to your tables without having to apply styles by hand or using extra loops/counting with your server side scripting.
Limit Characters in a Textarea with Prototype
Limit and display the number of characters available in a text area using my little add on script to the Prototype JavaScript library. Very easy to implement, and great feedback to your form filler-outers.
Zip Code, Phone Number and Replacing Empty Fields with Really Easy Validation
While using the Really Easy Validation JavaScript validation library I've accumulated a few custom validations that for US phone numbers, US zip codes, Canadian postal codes as well as replacing empty fields or fields that don't contain a numeric value. Good stuff!
First, Last, Active and Only List Styles With Prototype
It's easier than ever to apply the classes 'first, 'last', and 'active' to your navigation lists using the Prototype Javascript library. Of course this will only work for a JavaScript enabled environment but if you have a list that is out of control, or already requires Javascript, this might be your best solution.
Next Post
DIY Canvas Photography Backdrop ($20.34)
Previous Post
Quick and Dirty JavaScript Pop-Up Windows

Write a Comment

Take a moment to comment and tell us what you think. Some basic HTML is allowed for formatting.

Reader Comments

Be the first to leave a comment!