Forum Moderators: open

Message Too Old, No Replies

JavaScript Validation

how to know how many checkboxes are checked?

         

rick2004hunter

10:33 am on Oct 27, 2004 (gmt 0)

10+ Year Member



Hello
I am Rick
I am hitting my head from morning.
I would like to know how to know no of check boxes checked and ristrict it to some no say 2, if 1 check box is checked it should display saying alert("Minimun 2 required")
Please Help me out

mcguirec

11:59 am on Oct 27, 2004 (gmt 0)

10+ Year Member



Check this out....

[javascript.internet.com...]

Rambo Tribble

4:44 pm on Oct 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not sure why the original author incurred the overhead of the eval() method for the posted reference's function. It should work just fine like this:

function anyCheck(form) {
var total = 0;
var max = form.ckbox.length;
for (var idx = 0; idx < max; idx++) {
if (document.playlist.ckbox[idx].checked == true) {
total += 1;
}
}
alert("You selected " + total + " boxes.");
}