Copy link to clipboard
Copied
Hello,
What I'm looking for exactly is:
If the value in ("section_1_a") field = 3, then the check box ("a_1") has to checked automatically, and if the value is less than or greater than 3, ("a_1") must remain empty;
If ("section_1_a") value between 3 and 6, the check box ("a_2") has to checked automatically, and if not, ("a_2") must remain empty;
Another example, if the value in ("section_1_a") is 14, the check box ("a_9") has to checked automatically, and if not, ("a_9") must remain empty, and so on...
So what is the wrong in my code? It's working well if there is one check box, maybe (else if) need more adjustment!
var s1 = this.getField("section_1").value;
event.value = s1;
if (s1 = 3) {
this.getField("a_1").checkThisBox(0, true);
}
else if (3 < s1 < 6 ) {
this.getField("a_2").checkThisBox(0, true);
}
I need to fix it so I can complete the work on this sheet, and repeat (if) statments 13 times in each column
Thank you very much
Copy link to clipboard
Copied
The script has a number of issues.
1) It is only setting checkboxes, not un-setting them.
2) (3 < s1 < 6 ) is not a valid conditional
3) Why is "event.value" being set? This line should probably be deleted.
4) So where is this code? What field? Is it in a calculaton script? A validaiton script? this infomation is very important to understanding the issue.
Here's a re-write of the script that is intented to be place in the Custom Validation script of field "section_1_a". This script is triggered when the value of field "section_1_a" changes.
this.getField("a_1").checkThisBox(0, (event.value == 3));
this.getField("a_2").checkThisBox(0, (3 < event.value) && (event.value < 6 ));
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
The script has a number of issues.
1) It is only setting checkboxes, not un-setting them.
2) (3 < s1 < 6 ) is not a valid conditional
3) Why is "event.value" being set? This line should probably be deleted.
4) So where is this code? What field? Is it in a calculaton script? A validaiton script? this infomation is very important to understanding the issue.
Here's a re-write of the script that is intented to be place in the Custom Validation script of field "section_1_a". This script is triggered when the value of field "section_1_a" changes.
this.getField("a_1").checkThisBox(0, (event.value == 3));
this.getField("a_2").checkThisBox(0, (3 < event.value) && (event.value < 6 ));
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
1) Yes you are right, but it should be to set and unset the check boxes
2) I tried to test what I learned in Maths, but it did not work
3) because of the previous line: (var s1 = this.getField("section_1").value;), and I have to repeat the value from that field (section_1) in the current field (section_1_a)
4) It's a calculation script
Finally, Thanks @Thom Parker for re-wring the script, It's working very well. I only replace the equal sign with double equal sign.
This is the updated code:
this.getField("a_1").checkThisBox(0, (event.value == 3));
this.getField("a_2").checkThisBox(0, (3 < event.value) && (event.value < 6 ));
this.getField("a_3").checkThisBox(0, (event.value == 6));
this.getField("a_4").checkThisBox(0, (6 < event.value) && (event.value < 9 ));
this.getField("a_5").checkThisBox(0, (event.value == 9));
this.getField("a_6").checkThisBox(0, (9 < event.value) && (event.value < 11 ));
this.getField("a_7").checkThisBox(0, (event.value == 11));
this.getField("a_8").checkThisBox(0, (11 < event.value) && (event.value < 14 ));
this.getField("a_9").checkThisBox(0, (event.value == 14));
this.getField("a_10").checkThisBox(0, (14 < event.value) && (event.value < 17 ));
this.getField("a_11").checkThisBox(0, (event.value == 17));
this.getField("a_12").checkThisBox(0, (17 < event.value) && (event.value < 19 ));
this.getField("a_13").checkThisBox(0, (event.value >= 19));
Copy link to clipboard
Copied
Excellent Catch with the single "=",
The notation for the double comparison is mathematically correct. It just doesn't work for the rules of coding. In nearly all programming languages comparison operators are binary, i.e., they only operate on two operands at a time, and return a boolean result.
Use the Acrobat JavaScript Reference early and often

