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..in
loop, from the documentation at Mozilla Developer Network:
A for...in loop iterates over the properties of an object in an arbitrary order
As your checkboxes
are a nodeList, rather than an object, the for
loop should be used instead.
So, instead of for...in
, use:
for (var i=0,len=checkboxes.length;i<len;i++){
// do stuff
}
References:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.