Skip to main content
reneel70380514
Participant
August 8, 2019
Answered

Custom Calculation Script Help (no Javascript experience)

  • August 8, 2019
  • 1 reply
  • 1704 views

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:

This topic has been closed for replies.
Correct answer try67

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.

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
August 8, 2019

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.

reneel70380514
Participant
August 9, 2019

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!

try67
Community Expert
Community Expert
August 9, 2019

Yes, then you have to use quotes, and remove the "+" from the first line of code.