Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

- Home
- >
- Acrobat SDK
- >
- I am trying to set up a javascript "If" formula on...

New Here
,

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

Most Valuable Participant

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;

TOPICS

Acrobat SDK and JavaScript,
Windows

Community Guidelines

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

New Here
,

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

Most Valuable Participant

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;

TOPICS

Acrobat SDK and JavaScript,
Windows

Community Guidelines

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

QB1Sho

Jun 14, 2019
0
/t5/acrobat-sdk/i-am-trying-to-set-up-a-javascript-quot-if-quot-formula-on-a-form-and-keep-running-into-errors/td-p/10496123
2
Replies
2

Most Valuable Participant
,

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;

Community Guidelines

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

Reply

Loading...

try67

Jun 14, 2019
1
/t5/acrobat-sdk/i-am-trying-to-set-up-a-javascript-quot-if-quot-formula-on-a-form-and-keep-running-into-errors/m-p/10496124#M11749
QB1Sho
LATEST

New Here
,

Jun 14, 2019

Copy link to clipboard

Copied

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!

Community Guidelines

Reply

Loading...

QB1Sho

Jun 14, 2019
0
/t5/acrobat-sdk/i-am-trying-to-set-up-a-javascript-quot-if-quot-formula-on-a-form-and-keep-running-into-errors/m-p/10496125#M11750
Using the Community
Experience League
Terms of Use
Privacy Policy
Cookie preferences
AdChoices
Language:

- Deutsch
- English
- Español
- Français
- 日本語コミュニティ
- Português

Copyright © 2020 Adobe. All rights reserved.