It's kind of inefficient, because you're obtaining a reference to the form again every time the loop iterates. This is one of the most common causes of slowness in scripts. Better would be to get a single reference and store it:
Code:
function checked() {
var f = document.forms["myFormName"].elements;
for (var i = 0, f = document.forms['myFormName'].elements, e; e = f[i]; ++i)
if (e.checked) {
// The current box in the loop IS checked, do something here.
alert("Checkbox " + i + " is checked.");
}
}
Bookmarks