I’ve created a simple javascript to select all check boxes. It works in two browsers but not one. Can anyone help me with this script to make it compatible with IE8 or above.
<script language="JavaScript">
function toggle(source) {
checkboxes = document.getElementsByName('marked[]');
for(var i in checkboxes)
checkboxes[i].checked = source.checked;
}
</script>
<p>
<input type="checkbox" onClick="toggle(this)" /> Select All
</p>
Thanks,
Jonah
Try plain loop:
The
getElementsByNamereturns HTMLCollection which is not plain array, and probably treated differently in each browser. Most likely Firefox and Chrome returns the indices when using thefor(var i in checkboxes)loop while IE returns the items themselves – plain loop should solve this, as the basic syntax is the same for all browsers.