P
pieter.thoma
Hi,
I'm trying to count the number of selected checkboxes with the
following code, but I don't get any result, unless I explicitly
hardcode the form.chckbox-name.
This doesn't work:
function anyCheck(this) {
var total = 0;
var max = document.getElementById("cbox").length;
for (var idx = 0; idx < max; idx++) {
if (eval("document.getElementById[" + idx + "].checked") == true) {
total += 1;
}
}
alert("You selected " + total + " boxes.");
}
This does:
function anyCheck(form) {
var total = 0;
var max = form.ckbox.length;
for (var idx = 0; idx < max; idx++) {
if (eval("form.ckbox[" + idx + "].checked") == true) {
total += 1;
}
}
alert("You selected " + total + " boxes.");
}
I'm trying to count the number of selected checkboxes with the
following code, but I don't get any result, unless I explicitly
hardcode the form.chckbox-name.
This doesn't work:
function anyCheck(this) {
var total = 0;
var max = document.getElementById("cbox").length;
for (var idx = 0; idx < max; idx++) {
if (eval("document.getElementById[" + idx + "].checked") == true) {
total += 1;
}
}
alert("You selected " + total + " boxes.");
}
This does:
function anyCheck(form) {
var total = 0;
var max = form.ckbox.length;
for (var idx = 0; idx < max; idx++) {
if (eval("form.ckbox[" + idx + "].checked") == true) {
total += 1;
}
}
alert("You selected " + total + " boxes.");
}