Click to See Complete Forum and Search --> : counting checkboxes


kellerka
06-26-2003, 10:38 AM
I have a form with nine tables each with multple checkboxes. I need to count how many checkboxes the user checks in each table and display the number. Can anyone help? Thanks

Greelmo
06-26-2003, 11:19 AM
<script type="text/javascript">
var total=new Array();
for (i=0; i<=10; i++){
total[i]=0;}

function fncadd(theNumber)
{
total[theNumber]+=1;
}

and for each checkbox for the first table you say...
<input type="checkbox" onClick="fncadd(0);" name="boxName">Box Text

and the second table....
<input type="checkbox" onClick="fncadd(1);" name="boxName">Box Text

the third...
<input type="checkbox" onClick="fncadd(2);" name="boxName">Box Text

etc. Just add one to the number inside the parenthisis every time you are in a different table.


SO..
in the end you will wind up with an array with nine elements in it... all the elements are numbers. they are how many were clicked. However it will get screwy if the user checks something and then unchecks it. I hope this helped though.