Tally Checkboxes Checked

[Total: 0    Average: 0/5]

This will go through and find the total number of check boxes.

Body Code:

<form>
<input type=checkbox name=c1 CHECKED>
<input type=checkbox name=c2 CHECKED>
<input type=checkbox name=c3 CHECKED>
<input type=checkbox name=c4 CHECKED>
<input type=checkbox name=c5 CHECKED>
<input type=checkbox name=c6 CHECKED>
<input type=checkbox name=c7 CHECKED>
<input type=checkbox name=c8 CHECKED>
<input type=checkbox name=c9 CHECKED>
<input type=checkbox name=c10 CHECKED>
<input type=checkbox name=c11 CHECKED>
<input type=checkbox name=c12 CHECKED>
<input type=checkbox name=c13 CHECKED>
<input type=checkbox name=c14 CHECKED>
<input type=checkbox name=c15 CHECKED>
<BR>
<input type=checkbox name=u1>
<input type=checkbox name=u2>
<input type=checkbox name=u3>
<input type=checkbox name=u4>
<input type=checkbox name=u5>
<input type=checkbox name=u6>
<input type=checkbox name=u7>
<input type=checkbox name=u8>
<input type=checkbox name=u9>
<input type=checkbox name=u10>
<input type=checkbox name=u11>
<input type=checkbox name=u12>
<input type=checkbox name=u13>
<input type=checkbox name=u14>
<input type=checkbox name=u15>
<BR>
<input type=button onclick="doIt(this.form)" value="Find totals">
<BR>Clicked: <input size=5 type=text name=clicked value=0 onfocus=blur()>
<BR>Not Clicked: <input size=5 type=text name=notclicked value=0 onfocus=blur()>
</form>
<script>
function doIt(_f)
{
  var _countCK=0;
  var _countTL=0;
  for(var _obj = _f.firstChild; _obj ; _obj=_obj.nextSibling)
  {
    if(_obj.name!=undefined)
    {
      if(_obj.type=="checkbox")
      {
	    _countTL++;
	    if(_obj.checked)
          _countCK++;
      }
    }
  }
  _f.clicked.value=_countCK;
  _f.notclicked.value=0+_countTL-_countCK;
}
</script>

Times Viewed: 8

Leave a Reply

Your email address will not be published. Required fields are marked *