Reputation: 933
Here's a simple little javascript function that makes an array of all checkboxes (video) in my form (myform), and builts another array of the checkboxes that are checked. It works great unless there's only 1 checkbox in the form. In that case boxes is undefined. Shouldn't this work with document.myform.video.length is 1?
function toggle(main) {
boxes = document.myform.video.length;
alert(boxes);
var videos = [];
for (i=0; i<boxes; i++) {
document.myform.video[i].checked = main.checked;
}
}
Upvotes: 1
Views: 273
Reputation: 14949
no, if there is only one element by that name, the DOM would show it as the element not an array.
Upvotes: 4