i am trying to check/uncheck all checkboxes upon clicking on select all/deselect all checkbox as follows:
onclick="selectAll(document.getElementsByName('myForm:checkboxes'));"
and the JS function:
function selectAll(checkboxes)
{
for(var i in checkboxes)
checkboxes[i].checked = true;
}
function deselectAll(checkboxes)
{
for(var i in checkboxes)
checkboxes[i].checked = false;
}
and the HTML:
<input type="checkbox" value="15" name="myForm:checkboxes" id="myForm:checkboxes3:_1">
this code works fine in firefox, but in internet explorer 9 it doesn’t work.
Posting comment as answer:
A
for..inloop, from the documentation at Mozilla Developer Network:As your
checkboxesare a nodeList, rather than an object, theforloop should be used instead.So, instead of
for...in, use:References:
for (){/*...*/}.for..inloop.