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

Having Javascript issues for custom calculation (unchecked Checkboxes exporting value)

New Here ,
Jun 08, 2018 Jun 08, 2018

Copy link to clipboard

Copied

So right now, I'm trying to create a fillable pdf form in Adobe Acrobat Pro 2017 for the character sheet of a tabletop game so it automatically calculates the various stats. The problem I'm having is that I can't get a checkbox to export the value "Off" when it's unchecked like it's supposed to. Either that or my Javascript is garbage because I don't get Javascript at all.

What I want to happen is, if the checkbox is checked AND the value in textbox called "Ranks" is 1 or greater, then the text box called "Total" is equal to the sum of 3 + ranks + other boxes. Otherwise, if the checkbox is unchecked, regardless of the value of ranks, then the total should just be the ranks and other boxes.

Right now, the value of the total box is calculating as if the checkbox were always checked

Here's the current script as is for one of the total boxes:

var skill = +getField("Skill Check").value; //this is the checkbox

var ability = +getField ("Abl Modifier").value;

var rank = +getField("Ranks 1").value;

var misc = +getField("Misc Mod. 1").value;

if (skill="Yes" && rank>0) event.value = Math.floor(3+ability+rank+misc);

else if (skill="Off") event.value = Math.floor(ability+rank+misc)

TOPICS
Acrobat SDK and JavaScript , Windows

Views

208

Likes

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 08, 2018 Jun 08, 2018

On top of what was already mentioned you have another issue.

Why did you put a "+" symbol in this line?

var skill = +getField("Skill Check").value;

Do you know what that does? It converts the value to a number, but the value of that check-box is either "Off" or "Yes", so that will produce an error, as those values can't be converted to a number. As a result the value of the "skill" variable will be "NaN" (Not a Number). You need to remove that symbol from this line.

Likes

Translate

Translate
Community Expert ,
Jun 08, 2018 Jun 08, 2018

Copy link to clipboard

Copied

HI,

First point, the if statements don't appear to be correct ( based on the code above). The should have double equals rather than single

if ( skill == "Yes" && rank > 0) .....

else if ( skill == "Off" ) ......

And based on your text you want rank to be greater than 1 so it would probably need to be

if ( skill == "Yes" && rank > 1) .....

else if ( skill == "Off") ......

Hope that helps

Malcolm

Likes

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
Community Expert ,
Jun 08, 2018 Jun 08, 2018

Copy link to clipboard

Copied

On top of what was already mentioned you have another issue.

Why did you put a "+" symbol in this line?

var skill = +getField("Skill Check").value;

Do you know what that does? It converts the value to a number, but the value of that check-box is either "Off" or "Yes", so that will produce an error, as those values can't be converted to a number. As a result the value of the "skill" variable will be "NaN" (Not a Number). You need to remove that symbol from this line.

Likes

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 13, 2018 Jun 13, 2018

Copy link to clipboard

Copied

LATEST

Ah. Thank you! That fixed it. Like I said, I'm not too familiar with Javascript; I've been sort of learning on my own by googling basic Javascript functions. I also placed the double ='s just to be safe.

Likes

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