How could I count how many checkboxes are checked? There are around 100 checkboxes and I don't want the user to check more than 10.
Thanks,
| SitePoint Sponsor |
How could I count how many checkboxes are checked? There are around 100 checkboxes and I don't want the user to check more than 10.
Thanks,
ssegraves [at] gmail.com
On Image Use, Abuse, and Where We're Headed
stephan | XMLHttpRequest Basics
flickr | last.fm | Cogentas, LLC


Hey Hartmann,
Try something like this:
Hope that helps,Code:<script> var number=0; function checkit(){ number=0; for(j=0;j<document.forms[0].elements.length;j++){ if(document.forms[0].elements[j].type=="checkbox" && document.forms[0].elements[j].checked==true){ number++; }} if(number>10){ alert('You\'ve checked more than 10 checkboxes. Only check ten'); }} </script>
aDog![]()
Moderator at www.javascriptcity.com/forums/


Did this help you?
Moderator at www.javascriptcity.com/forums/
Worked like a charm!Many thanks!!
![]()
ssegraves [at] gmail.com
On Image Use, Abuse, and Where We're Headed
stephan | XMLHttpRequest Basics
flickr | last.fm | Cogentas, LLC


Great, just remember to add to my karma
aDog![]()
Moderator at www.javascriptcity.com/forums/
I gave you some the day you replied...![]()
ssegraves [at] gmail.com
On Image Use, Abuse, and Where We're Headed
stephan | XMLHttpRequest Basics
flickr | last.fm | Cogentas, LLC
Bookmarks