Code to check and uncheck checkbox
Copy link to clipboard
Copied
Good Morning everyone
I am creating a form with many check box and I have two button one is NONE and the other one is ALL
I would like to be able to Uncheck all check box if I click NONE and I would like to be able to check all
check box if I click ALL
and I tought I had to use javascript code to be able to do that on both buttons ( NONE and ALL )
but I have try different code and didn't work
Copy link to clipboard
Copied
You do but it is not just one statement. Depending upon how you have named your check boxes and what value you have assigned to them when checked will need to be used to check or uncheck the check boxes. An unchecked check box field has a value of "Off".
What code have you tried?
The custom JavaScript code will depend upon how you have named the fields and what value you have assigned to the "Checked Value".
The easiest would be to use hierarchical field names and all field have the same checked value.
// using hierarchical field names;
// check all;
// field names are "Check Box.#";
// get the parent field object;
var oAll = this.getField("Check Box");
// create an array of individual field objects;
var aAll = oAll.getArray();
// set each dhild field's value to "Yes";
for(var i = 0; i < aAll.length; i++)
{
aAll.value = "Yes";
}
You would uncheck them by setting the value to "Off".
The code get more complex if you use individual and different names for each field or assign different values for the "Checked Value".

