Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Counting checkboxes

Status
Not open for further replies.

timjwild

Programmer
Oct 13, 2000
10
GB
I've searched through this forum and have seen plenty of discussions on how to check if a checkbox is ...erm checked.

My problem is slightly different. I have a page with 100 possible selections from which the user may only select 25. How do I count the number of selected boxes and flag an alert if the user exceeds 25?

Thanks

Tim
 
...And I need it to work in NS6!

Thanks

Tim
 
i'm giving you the generic way to do so, because i still haven't tested nn6 (yessss, shame on me) - but it should be easy to adapt - let me know if you have trouble doing so, i'll try to help
the idea is to loop thru the form.elements array - for each element, check if the type is "checkbox", if yes, check if it's checked, if yes, then increment the counter :
function how_many_checked(){
counter = 0;
for (index=0: index < formname.elements.length; index++){
if (formname.elements[index].type==&quot;checkbox&quot;)
if (forname.elements[index].checked)
counter++;
} // end for loop
if (counter > 25) {
alert (&quot;hey that's too many boxes checked&quot;)
return false
}
return true;
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top