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.
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.
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.
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)
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.
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.
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.
Copy link to clipboard
Copied
Sure. You can do it like this:
his.getField("unqualified").checkThisBox(0, (event.value!="" && Number(event.value)<=23));
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?
Copy link to clipboard
Copied
Replace it.
Copy link to clipboard
Copied
It worked!! Thanks for all of your assistance.