Copy link to clipboard
Copied
Dear All,
I hope somebody can help me. I'm not a programmer but need to create some calculations within a PDF form. I am trying to calculate the number of daily calories required based on a number of criteria. I have managed to make the calculation work if I am just looking at the values of each field but I need to take into account if the user is male or female. For example: If the user is male then use: 1066 + (6.23 * v4) + (12.7 * v3) - (6.8 * v2) and If the user is Female use: 66 + (6.23 * v4) + (12.7 * v3) - (6.8 * v2).
I am performing the calculation in the Calories field.
This is what I have so far which does work but doesn't have the capacity to change between male or female.
(function() {
var v1 = +getField("Gender").value;
var v2 = +getField("Age").value;
var v3 = +getField("Height").value;
var v4 = +getField("Weight").value;
var v5 = +getField("Activity").value;
var result = 66 + (6.23 * v4) + (12.7 * v3) - (6.8 * v2);
event.value = result;
})();
Thank you in advance.
Copy link to clipboard
Copied
Here's an article on how to write an if statement in a calculation:
https://acrobatusers.com/tutorials/conditional-execution
Copy link to clipboard
Copied
Thanks Thom,
I nearly have it working with:
var v1 = this.getField("Gender").valueAsString;
var v2 = this.getField("Age").value;
var v3 = this.getField("Height").value;
var v4 = this.getField("Weight").value;
var v5 = this.getField("Activity").value;
if( v1 ="Female") event.value = 1066 + (6.23 * v4) + (12.7 * v3) - (6.8 * v2);
else event.value = 66 + (6.23 * v4) + (12.7 * v3) - (6.8 * v2);
The problem is that it only recognises the 'Female' equation. If I change the Gender to Male it doesn't change the equation. Could this be something to do with the lack some sort of 'After Update', 'Requery' or 'Refresh function assigned to the other boxes?
Copy link to clipboard
Copied
Replace:
if( v1 ="Female")
With:
if( v1=="Female")
Copy link to clipboard
Copied
Thanks try67,
Unfortunately the Calories field is still not updating after update of Gender Field.
Copy link to clipboard
Copied
Press Ctrl+J and check the JS Console for errors. Also, you have to change the value of one of the fields for it to "kick in".
Copy link to clipboard
Copied
One more thing: Since the Gender field is a drop-down you should enable its option to commit the selected value immediately (under Properties - Options). Otherwise it will only update once you leave the field, not the moment a selection is made.
Copy link to clipboard
Copied
Same goes for Activity, although it doesn't seem like you're actually using its value in the formula (v5 is declared but not used).
Copy link to clipboard
Copied
Dear try67,
Thank you so much for your help.
The suggestions didn't work with the drop down list but I changed it to a text field and the if statement now works.
Copy link to clipboard
Copied
That's strange... If you want to share the file with me I'll be happy to check out what the issue is.
You can upload it to Dropbox, Google Drive, Adobe Cloud, etc., and post the link to it here, or you can email it to me to try6767 at gmail.com.
Copy link to clipboard
Copied
Thank you try67 - I have sent you a link.