Forum Moderators: open
What I want to do is have one checkbox select more checkboxes. But that’s simple, I did find that on this forum :)
What I have is a page with 3 groups of 5 checkboxes. Each group has to have a checkbox that checks all the checkboxes in only its own group. But they have to be in one and the same form...
What I am actually looking for is a (java?) script to select multiple checkboxes independent of the form it is in. For example one checkbox checks all checkboxes with id=1..... another checkbox checks all checkboxes with id=2... despite of them being in the same or in different forms... so I don’t want the form name to play a part in the script.
Can anyone help me?
Build an array of all the inputs in the container:
inputArray = document.getElementById('container').getElementsByTagName('INPUT'); If you have other inputs then you can use a class on the checkboxes and use that to select the checkboxes:
for(i=0;i<inputArray.length;i++) {
if(inputArray[i].className=='checkboxClassName') {
inputArray[i].checked = 'checked';
}
}
That is the principle at it's most basic. You can make the scipt more intellegent by seeing if they are checked and if so unchecking them (and vice versa). You can do the same on the control checkbox, if it is checked then uncheck everything and again vice versa.
HTH