Check Boxes Count number checked

message from Mel Lockett on 21 Jul 2004
I have a webpage with 20 questions on it each having a unique check box.
Visitors are asked to check the question if the conform.
At the foot of the page, I want to show the total number of checkboxes that
are checked.
How do I achieve this?

Mel Lockett
 
Mick White replied to Mel Lockett on 21 Jul 2004
<script type="text/javascript">
function howManyCheckboxesChecked(frm){
var f=frm.length,boxesChecked=0;
while(f--){
if(frm[f].type=="checkbox" && frm[f].checked){
boxesChecked++;
}
return boxesChecked;
}
</script>

The function returns the number of checkboxes checked. (Just pass the
form object as a parameter to the function)

<p id="foo" ></p>
<a href="javascript: void()"
onclick="document.getElementById('foo').innerHTML=
howManyCheckboxesChecked(document.forms[0]);return false;">click</a>

Mick
 
Paul Whitham TMM replied to Mel Lockett on 22 Jul 2004
If you want this to appear on the same page, I would suggest you look at the
calculate form from www.yaromat.com
 

Archived message: Check Boxes Count number checked (Macromedia Dreamweaver)