I have an HTML page with multiple checkboxes.
I need one more checkbox by the name \"select all\". When I select this checkbox all checkboxes in the HTML page must b
My simple solution allows to selectively select/deselect all checkboxes in a given portion of the form, while using different names for each checkbox, so that they can be easily recognized after the form is POSTed.
Javascript:
function setAllCheckboxes(divId, sourceCheckbox) {
divElement = document.getElementById(divId);
inputElements = divElement.getElementsByTagName('input');
for (i = 0; i < inputElements.length; i++) {
if (inputElements[i].type != 'checkbox')
continue;
inputElements[i].checked = sourceCheckbox.checked;
}
}
HTML example:
All of them
Spacey, Kevin
Firth, Colin
Johansson, Scarlett
I hope you like it!