Count Checkboxes/RadioBoxes Selected

[Total: 0    Average: 0/5]

This example counts the number of radio boxes that are selected.

Body Code:

<script>
function cntprimary(cnt){
cnt=0;
   for(i=1; i<=8; i++){
   var enc=eval("document.nameofform.checkbox"+i+".checked");
     if(enc){
         cnt++;
     }
   }
   return cnt;
}
</script>
<form name=nameofform>
<input type="radio" name="checkbox1" value="check me">
<input type="radio" name="checkbox2" value="check me">
<input type="radio" name="checkbox3" value="check me">
<input type="radio" name="checkbox4" value="check me">
<input type="radio" name="checkbox5" value="check me">
<input type="radio" name="checkbox6" value="check me">
<input type="radio" name="checkbox7" value="check me">
<input type="radio" name="checkbox8" value="check me">
</form>
<BR><a href="javascript:alert(cntprimary())">how many?</a>

Times Viewed: 0

Leave a Reply

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