Body Mass Calculator

If you have a web site that deals with health or diet then here is a BMI calculator that may make a good addition to your site. For those looking at this calculator not familiar with body mass index, it is the the ratio of body weight to the square of your height and is a general indication of whether someone is overweight.

The first thing to note with this calculator is that it has a PHP fallback built in so that the calculator will still work even for those visitors who have JavaScript disabled. In addition the script is designed to be reasonably unobtrusive. None of the JavaScript is in global scope except for the submit event on the form and the id values chosen are ones that are hopefully very unlikely to appear elsewhere in your page. If for some reason one or more of the ids do clash then simply change every reference to that id to a different value to resolve the clash.

To install the calculator on your own site first download and unzip the files. You can then modify the bmi.php file that contains the form to add whatever other content that you want to appear on the same page or if you prefer you can copy and paste the various parts of that page into the page where you want to install the calculator.

Most of the code is needed to validate the values that your visitor enters into the form in order to make sure that the values are numeric and within a reasonable range. The actual calculation only requires a single line of code.

 

This article written by Stephen Chapman, Felgall Pty Ltd.

go to top

FaceBook Follow
Twitter Follow
Donate