Copy link to clipboard
Copied
Hello.
I am new to Javascript in PDF documents.
I have a form with multiple checkboxes set in specific areas.
I created a button that I want to uncheck all buttons in a specific area.
I named the buttons "Potential#0-4" (Potential1, Potential2, etc.).
I found a javascript that I wanted to change all Checkboxes to "unchecked" when clicked (mouse up), but when I press the button, nothing happens:
function unCheckAll () {
var oAll = this.getField("Potential");
var aAll = oAll.getArray();
for(var i = 0; i < aAll.length; i++)
{
aAll.value = "Off";
}
}
unCheckAll();
How can I make the button uncheck all checkboxes with "Potential" in their name?
Thank you!
Copy link to clipboard
Copied
To use the "getArray()" function the fields must be named using group notation.
For example:"Potential.check1", "Potential.check2", etc.
Do this and then you can use this one line of code to reset the checkboxes
this.resetForm("Potential");
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Try this:
for (var i = 0; i <=4; i++) {
var f = this.getField("Potential"+i);
f.value = "Off";
}
Copy link to clipboard
Copied
To use the "getArray()" function the fields must be named using group notation.
For example:"Potential.check1", "Potential.check2", etc.
Do this and then you can use this one line of code to reset the checkboxes
this.resetForm("Potential");
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Thanks! That worked like a charm!
Copy link to clipboard
Copied
Hi Thom, I've just used this and it works - however I need the checkbox to stay ticked or on when selected. So it resets the other checkboxes in the group, but itself is checked (like a "none of the above" option). What code can be added here to this? Thank you
Copy link to clipboard
Copied
Make the "None of the Above" checkbox the default. Then it will be checked when the fields are reset.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Within the group of checkbox I have to limit selection to 3 maximum, so when I make "None of the above" the default, this counts towards the three. Can you think of anyway to get around this? I.e. Three options are selected, then None is selected, and the three options clear. OR, None is selected, then another option is selected, and None clears.
This is what I'm using to limit the selections:
var nMax = 3;
if(event.target.value != "Off")
{
var nCnt = 0;
this.getField("ASix").getArray().forEach(function(a){if(a.value != "Off") nCnt++;});
if(nCnt > nMax)
event.target.value = "Off";
}

