Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Custom Calculation Script Help (no Javascript experience)

New Here ,
Aug 08, 2019 Aug 08, 2019

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:

Screen Shot 2019-08-08 at 2.57.30 PM.png

TOPICS
PDF forms
1.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Aug 08, 2019 Aug 08, 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.

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 08, 2019 Aug 08, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 08, 2019 Aug 08, 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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 09, 2019 Aug 09, 2019

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 09, 2019 Aug 09, 2019

Awesome, it works. Thanks so much for your time and help. You've saved me HOURS! Much appreciated!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 09, 2019 Aug 09, 2019

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 09, 2019 Aug 09, 2019
LATEST

Go to the Properties of the drop-down field and under Option tick the "Commit selected value immediately" box.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines