Field value to determine which checkbox is selected

New Here ,
Jul 08, 2018

Copy link to clipboard

Copied

Hello,

I'm trying to write a script to have one of four check boxes selected based on the value entered into a field.  I have pasted a picture of the portion of the PDF that I'm trying to write the script.  I want the "Grand Total" field to be the trigger so I put the following code into the custom validation script of this field.

this.getField("unqualified").checkThisBox(0, (event.value <="23"));

this.getField("marksman").checkThisBox(0, (event.value >="24") || (event.value <=28));

this.getField("sharpshooter").checkThisBox(0, (event.value >="29") || (event.value <=35));

this.getField("expert").checkThisBox(0, (event.value >="36"));

I'm unsure how to write the code for a number range (i.e. 24 - 28; 29 - 35) therefore multiple check boxes are selected using my code.  I need only one check box selected based on the "Grand Total" field.

Checkbox Selection.JPG

TOPICS
Acrobat SDK and JavaScript, Windows

Views

119

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

Field value to determine which checkbox is selected

New Here ,
Jul 08, 2018

Copy link to clipboard

Copied

Hello,

I'm trying to write a script to have one of four check boxes selected based on the value entered into a field.  I have pasted a picture of the portion of the PDF that I'm trying to write the script.  I want the "Grand Total" field to be the trigger so I put the following code into the custom validation script of this field.

this.getField("unqualified").checkThisBox(0, (event.value <="23"));

this.getField("marksman").checkThisBox(0, (event.value >="24") || (event.value <=28));

this.getField("sharpshooter").checkThisBox(0, (event.value >="29") || (event.value <=35));

this.getField("expert").checkThisBox(0, (event.value >="36"));

I'm unsure how to write the code for a number range (i.e. 24 - 28; 29 - 35) therefore multiple check boxes are selected using my code.  I need only one check box selected based on the "Grand Total" field.

Checkbox Selection.JPG

TOPICS
Acrobat SDK and JavaScript, Windows

Views

120

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
Jul 08, 2018 0
New Here ,
Jul 08, 2018

Copy link to clipboard

Copied

I did some more research on the internet and found that I only needed to replace "||" with "&&" and now the code works fine and only selects the correct checkbox.

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
Reply
Loading...
Jul 08, 2018 0
Most Valuable Participant ,
Jul 09, 2018

Copy link to clipboard

Copied

You should test it more carefully, because there are problems with your code.

You don't see a problem with this statement, for example?

(event.value >="29") && (event.value <=35)

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
Reply
Loading...
Jul 09, 2018 0
New Here ,
Jul 09, 2018

Copy link to clipboard

Copied

I did more texting and do see a problem but I am unsure how to correct it.  Multiple boxes get checked when the Grand Total number goes up.

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
Reply
Loading...
Jul 09, 2018 0
Most Valuable Participant ,
Jul 09, 2018

Copy link to clipboard

Copied

If you want to do mathematical comparisons you can't put quotes around the numbers. That makes them into strings and your comparisons won't work.

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
Reply
Loading...
Jul 09, 2018 0
New Here ,
Jul 09, 2018

Copy link to clipboard

Copied

Wow...I've been looking at this screen so long that I didn't even notice I had quotes around the first set of numbers for each line.  Thanks.

Is it possible to keep the "Unqualified" checkbox unchecked if the "Grand Total" box is blank?  I understand the range for "Unqualified" is 0 - 23, but I want the entire form to be blank when it is first opened. 

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
Reply
Loading...
Jul 09, 2018 0
Most Valuable Participant ,
Jul 09, 2018

Copy link to clipboard

Copied

Sure. You can do it like this:

his.getField("unqualified").checkThisBox(0, (event.value!="" && Number(event.value)<=23));

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
Reply
Loading...
Jul 09, 2018 0
New Here ,
Jul 09, 2018

Copy link to clipboard

Copied

I tried that but the box is still checked.  Do I replace the original line for "unqualified" or do I add this line to what is already there?

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
Reply
Loading...
Jul 09, 2018 0
Most Valuable Participant ,
Jul 09, 2018

Copy link to clipboard

Copied

Replace it.

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
Reply
Loading...
Jul 09, 2018 0
New Here ,
Jul 10, 2018

Copy link to clipboard

Copied

It worked!!  Thanks for all of your assistance.

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
Reply
Loading...
Jul 10, 2018 0