Mel Lockett wrote:
Quote:
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? |
<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