<!-- BMI Finder --> <!-- This goes in the HEAD of the html file --> <script language="javascript" type="text/javascript"> <!-- Copyright 2002, Sandeep Gangadharan --> <!-- For more free scripts go to http://sivamdesign.com/scripts/ --> <!-- function theBMI() { var p = document.bmi.pounds.value; var k = document.bmi.kilos.value; var i = document.bmi.inches.value; var f = document.bmi.feet.value; var c = document.bmi.cms.value; theWeight = (p / 2.205) || k; theHeight = (((f * 12) + (i * 1)) * 0.0254) || (c * 0.01); document.bmi.answer.value = (Math.round((theWeight) / (theHeight * theHeight))); if ((k >= 1) && (p >= 1)) { alert('Fill in either Kilos or Pounds, not both!'); return false; } if ((c >= 1) && (f >= 1)) { alert('Fill in either in Feet or Centimeters, not both!'); return false; } if ((i >= 1) && (c >= 1)) { alert('Fill in either in Feet or Centimeters, not both!'); return false; } if ((f == "") && (c == "")) { alert('You have not filled in the Height field!'); return false; } if ((p == "") && (k == "")) { alert('You have not filled in the Weight field!'); return false; } if ((f == "") && (i >= 1)) { alert('You have not filled in the Feet field!'); return false; } var ans = document.bmi.answer.value; if (ans < 20) { document.bmi.comment.value = "You are underweight"; } if (ans >= 20 && ans <= 22) { document.bmi.comment.value = "Desirable Weight"; } if (ans >= 23 && ans <= 25) { document.bmi.comment.value = "Acceptable but not desirable"; } if (ans >= 26 && ans <= 30) { document.bmi.comment.value = "Prone to health risks"; } if (ans > 30) { document.bmi.comment.value = "High risk"; } if (document.bmi.inches.value > 11 && document.bmi.inches.value <= 23) { (document.bmi.inches.value = parseInt(document.bmi.inches.value) - 12) && (document.bmi.feet.value = parseInt(document.bmi.feet.value) + 1); } if (document.bmi.inches.value > 23) { (document.bmi.inches.value = parseInt(document.bmi.inches.value) - 24) && (document.bmi.feet.value = parseInt(document.bmi.feet.value) + 2); } } //--> </script> <!-- This goes in the BODY of the html file --> <center> <table width="330" border="0" bgcolor="#cccccc" cellpadding="3" cellspacing="0"> <tr> <td colspan="2" bgcolor="#000080"> <font face="verdana, arial, helvetica, sans-serif" size="1" color="#ffffff"> <b>Body Mass Index Finder</b> </font> </td> </tr> <form name="bmi"> <tr> <td width="150"> <font face="verdana, arial, helvetica, sans-serif" size="1"> <b>Weight:</b> <input type="text" name="kilos" size="3" maxlength="5" onFocus="select()"> kgs. &nbsp;&nbsp;<font color="#ff0000"><b>OR</b></font> </font> </td> <td> <font face="verdana, arial, helvetica, sans-serif" size="1">&nbsp; <input type="text" name="pounds" size="4" maxlength="6" onFocus="select()"> lbs. </font> </td> </tr> <tr> <td width="150"> <font face="verdana, arial, helvetica, sans-serif" size="1"> <b>Height:</b> <input type=text name="feet" size="1" maxlength="1" onFocus="select()"> Ft.&nbsp; <input type=text name="inches" size="2" maxlength="2" onFocus="select()"> In. </font> </td> <td> <font face="verdana, arial, helvetica, sans-serif" size="1">&nbsp;<font color="#ff0000"><b>OR</b></font> &nbsp;&nbsp; <input type="text" name="cms" size="3" maxlength="3" onFocus="select()"> Centimeters. </font> </td> </tr> <tr> <td width="150"> <input type="button" value="Get BMI" style="font-size: 9pt" onclick="theBMI()"> </td> <td width="190" align="right"> <font face="verdana, arial, helvetica, sans-serif" size="1"> <b>Body Mass Index:</b></font> <input type="text" name="answer" size="3" style="font-size: 9pt">&nbsp; </td> </tr> <tr> <td colspan="2"> <font face="verdana, arial, helvetica, sans-serif" size="1"> <b>Comment:</b></font> <input type="text" name="comment" size="29"> </td> </tr> </form> </table> </center>