Skip to main content
Known Participant
November 27, 2024
Question

BMI calculated or entered manually

  • November 27, 2024
  • 2 replies
  • 261 views

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.

 

2 replies

try67
Community Expert
Community Expert
November 27, 2024

In an On Blur event this line has no effect:

 

event.rc = false;
PDF Automation Station
Community Expert
Community Expert
November 27, 2024

You should have a custom calculation script in each field that you want a calculated result, not a blur event and event.rc doesn't need to be used.   This article will help with the custom calculation for BMI that also allows a manual entry.