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

I am trying to set up a javascript "If" formula on a form and keep running into errors.

New Here ,
Jun 14, 2019 Jun 14, 2019

Copy link to clipboard

Copied

Good Morning/Afternoon!

I am trying to set up a calculation on a form that is based of an "if/Else" format.  The calculation in words would look something like this:

Skill Calculation:

If “Trained Skill 1”>0;

“bonus 1 = “Dex Mod” + “Trained Skill 1” + “Skill Misc Mod 1” + “Addtl Misc Mod 1”

Else

“bonus 1” = 0

If it were in excel it would look like this as far as format and expected outcome:

As you can see from the Excel snip, Row 2 shows that C1 ("Trained Skill 1") has a 1 in the column.  As a result, the sum of B2 ("Ability Mod"), C2 ("Trained Skill 1"), D2 ("Skill Misc Mod 1"), and E2 ("Addtl Misc Mod 1") is calculated and placed in A1 ("Bonus 1")

Conversely, Row 3 shows that C2 ( "Trained Skill 1") has a 0 in the column.  As a result, the sum of B2 ("Ability Mod"), C2 ("Trained Skill 1"), D2 ("Skill Misc Mod 1"), and E2 ("Addtl Misc Mod 1") is NOT calculated and a 0 is placed in B1 ("Bonus 1")

Can anyone help me create a javascript formula depicting this action?   I cant seem to get a working script.   

Thank you tremendously in advance!


Best!

JLD

TOPICS
Acrobat SDK and JavaScript , Windows

Views

250

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Jun 14, 2019 Jun 14, 2019

You can use this code as the custom calculation script of "bonus 1":

if (Number(this.getField("Trained Skill 1").valueAsString)>0)

    event.value = Number(this.getField("Dex Mod").valueAsString) + Number(this.getField("Trained Skill 1").valueAsString) +

     Number(this.getField("Skill Misc Mod 1").valueAsString) + Number(this.getField("Addtl Misc Mod 1").valueAsString);

else event.value = 0;

Votes

Translate

Translate
Community Expert ,
Jun 14, 2019 Jun 14, 2019

Copy link to clipboard

Copied

You can use this code as the custom calculation script of "bonus 1":

if (Number(this.getField("Trained Skill 1").valueAsString)>0)

    event.value = Number(this.getField("Dex Mod").valueAsString) + Number(this.getField("Trained Skill 1").valueAsString) +

     Number(this.getField("Skill Misc Mod 1").valueAsString) + Number(this.getField("Addtl Misc Mod 1").valueAsString);

else event.value = 0;

Votes

Translate

Translate

Report

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 ,
Jun 14, 2019 Jun 14, 2019

Copy link to clipboard

Copied

LATEST

Wow!  Such a fast response and right on the money!  Worked like a dream.  Thank you try67​ , you are a great asset to this community.  I was reading your past posts and was close...I just had a few missing things! 

Thank you a ton!  Have a great weekend!

Votes

Translate

Translate

Report

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