Copy link to clipboard
Copied
Hi all,
Really hoping someone could help me. I'm thinking this should be much more straight forward so I'm probably missing something very simple.
I'm working on an Acrobat Pro DC fillable form. The drop-down with two options is the condition and would like the Months24 field to calculate differently based on which dropdown is selected. The calculation is a basic dollar amount multiplied by a rate to output a monthly payment.
Below is what I'm trying to use in the Custom Calculation Script for the field I would like to be calculated (I was researching & testing what I found on these forums):
var a=+this.getField("DeferralOption").value;
if(a=="3") event.value=(Price*TMDRate24);
else if(a=="6") event.value=(Price*SMDRate24);
Here is a screenshot of my form:

Copy link to clipboard
Copied
You have a couple of issues.
1. If "a" is a number then you should compare it to numbers, not strings. So drop the quotes around "3" and "6" in lines 2 and 3.
2. You have to access the value of a field like you did with "DeferralOption". You can't just write its name, like you're doing with Price, TMDRate24 and SMDRate24.
Copy link to clipboard
Copied
You have a couple of issues.
1. If "a" is a number then you should compare it to numbers, not strings. So drop the quotes around "3" and "6" in lines 2 and 3.
2. You have to access the value of a field like you did with "DeferralOption". You can't just write its name, like you're doing with Price, TMDRate24 and SMDRate24.
Copy link to clipboard
Copied
Thank you, this fixed it! If I instead list "3 Months at $0" & "6 Months at $99" as the drop-down options and in the formula for If & Else, do I need to have the "" around them? If so, is there something else I need to do to make this work? When I tryp adjusting the options as such, the code doesn't work. Worst case, I'll just still with 3 & 6, without the "", as you advised. Thanks again!
Copy link to clipboard
Copied
Yes, then you have to use quotes, and remove the "+" from the first line of code.
Copy link to clipboard
Copied
Awesome, it works. Thanks so much for your time and help. You've saved me HOURS!
Much appreciated!
Copy link to clipboard
Copied
Hi, one more question. For the dropdown, I'm trying to get the calculations to appear automatically, once the dropdown item is clicked/changed. Is this possible?
Currently, you have to click somewhere in the PDF for the calculation to take/appear, after switching the dropdown.
I think I'm missing a field setting adjustment.. Thanks again!
Copy link to clipboard
Copied
Go to the Properties of the drop-down field and under Option tick the "Commit selected value immediately" box.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more