I am trying to get a form text box to show the result of a calculation. I have 3 text boxes. Each one has a user entered numeric value. A fourth text box will show the value of the three box calculation. the result will show the form users BMI (body mass index). the formula is (Weight (lb) / (Height (in))2) x 703/(lb/in2)
Form field for weight is named lb; height filed is named ft; inch is named in.
Any idea how to write this in the field validate so that the result shows up in the "BMI" field? Thanks
Why not just use the compute tab for the BMI field?
Since you have a divisor that will have a zero value you need to use an "if" statement to prevent division by zero or a null value.
var nWeight = this.getField("Weight").value; // weight in lbs;
var nHeight = this.getField("Height").value; // height in inches;
event.value = "";
if(nHeight != 0)
// BMI = ( Weight / Height^2) / 703;
event.value = (nWeight / Math.pow(nHeight,2)) * 703;
Hi. Tried the script but nothing showed up in the calculated BMI field. Thanks for your input though.
Here's a screenshot of the fields in that form. I'm placing the formula in the "Calculated BMI" field.
You need to enter a value into one of the fields for it to "kick in", and if nothing happens (or you're getting the wrong result), press Ctrl+J and check the window that opens for error messages.
You are now showing the height as feet and inches but only described the height as inches. I assume you know how to convert feet and inches to inches.
Yep, know how to convert ft to inches. However, the user has to enter height in one field then inches in the second field. So the formula I've used is height (feet) value times 12 plus the inches value which gives me the value for total height in inches. BTW, after each time i change the script in the "custom calculation script" tab field I click on preview, add values to the fields and nothing shows up in the BMI field.
Check the calculation order.
Thanks, Bernd. I did that but still no success.
Can you share a link of the form?
Bernd, this may help... here's the formula from the excel spreadsheet i'm trying to duplicate in the form field.
where E9=weight in lbs, A9=feet, C9=inches
The following more extensive script will report any field access errors and round the field's stored result to 1 decimal place.
// purpose get field objec and report if error occurs;
// return field object from document object for field name;
var oField = oDoc.getField(cName);
if(oField == null)
app.alert("Error accessing field named " + cName, 1, 0);
} // end GetField function;
var oHeightFt = GetField(this, "ft"); // height in feet;
var oHeightIn = GetField(this,"in"); // height in inches above feet value;
var oWeight = GetField(this, "lb"); // weight in lbs;
event.value = ""; // clear field;
// compute if input fields not null;
if(oHeightFt != null && oHeightIn != null && oWeight != null)
var nHeight = (oHeightFt.value * 12) + oHeightIn.value; // convert height in feet and inches to height in inches only;
// calculate BMI if height not zero;
if(nHeight != 0)
var nBMI = (oWeight.value / Math.pow(nHeight, 2)) * 703; // compute BMI
event.value = Number(util.printf("%,101.1f", nBMI)); // round resutl to 1 decimal palce;
} // end height not zero;
} // if inputs field not null;
// end custom calculation script for CalcBNI field;
Awesome. Your script worked perfectly. Thank you so much for the help, really appreciate the time you spent doing this. Hope all is well with you and yours.
There is no calculation in the form.
See Compute BMI with comments for an example with working code and comments about how to better make use of form fields and their properties. I have also included an Excel file that shows how to suppress the divide by zero error in Excel. Unlike Excel PDF forms stop functioning when a divide by zero event occurs.
Hi guys, I am new to Adobe form and java etc.
I tried to use this formula but I have little bit different situation as I would like to create BMI calculator but based on height in cm (not innches/feet) are you able to help me with this please as I tried to change some parameters myself but still not successful 😞
BMI in the red circle should be 26.4 but it is showing different value 😞 - photo attached
Your help will be apprieciated :)))
Thank you in advance.
What script does you use?
Hi Bernd. thank you for stooping by 🙂
I think : Custom calculation script will be the best for this?
any chance you can help me with this script, how to change formula for weight / (height in cm )2 ?