Checking all the boxes
To check all of the options, you can use:
<input type="button" name="Button" value="Check All" onclick="checkAll('test_form', true)" />
Or to uncheck all of the options you can use:
<input type="button" name="Button" value="Uncheck All" onclick="checkAll('test_form', false)" />
The above examples will check and uncheck all of the checkboxes that are in a form with the ID 'test_form'
.
function checkAll(frm, checkedOn) {
// have we been passed an ID
if (typeof frm == "string") {
frm = document.getElementById(frm);
}
// Get all of the inputs that are in this form
var inputs = frm.getElementsByTagName("input");
// for each input in the form, check if it is a checkbox
for (var i = 0; i < inputs.length; i++) {
if (inputs[i].type == "checkbox") {
inputs[i].checked = checkedOn;
}
}
}
Download
Download the examples Check all checkbox options example 1 and Check all checkbox options example 2 now!
Got something to say?
Join the discussion! You know how these things work; enter your details and comments below and be heard.
Comments 0
There are no comments on this yet.