BMI calculated or entered manually
I have a BMI (body mass index) field that get calculated when the user enters the weight and height,:
weight / ((height/100)*(height/100));
But sometime we would like to just enter the BMI manually because we don't know their weight and height.
There is another layer of difficulty because the BMI is broken down into BMIwhole and BMIdecimal.
I put the following code on blur in the kg field::
var weight = this.getField("kg").value;
var height = this.getField("cm").value;
if (this.getField("BMIwhole").value == "")
{
if(weight != "" && height != ""){
calcul = weight / ((height/100)*(height/100));
calculDecimal = calcul;
partieEntiere = Math.floor(calcul);
if(partieEntiere<=0) {partieEntiere="";}
this.getField("BMIwhole").value = partieEntiere;
this.getField("BMIdec").value = Math.round(10*(calculDecimal-partieEntiere));
{if (this.getField("BMIdec").value == "10")
{
this.getField("BMIwhole").value = partieEntiere+1;
this.getField("BMIdec").value = "0"
}}
}} else {
this.getField("BMIwhole").value = "";
this.getField("BMIdec").value = "";
}
if (this.getField("BMIwhole").value >= "1");
{
event.rc = false;
}But when I just enter the BMI manually, it will be deleted on the next keystroke.
