...

View Full Version : counting number of clicks



cwl157
07-15-2003, 05:22 PM
I am trying to put in a counter that every time someone clicks a checkbox it will count up by one. If someone clicks on the checkbox again i still only want it counted once. If someone clicks but not on the check box i don't want it to count. If i can not do this with checkboxes does anyone else know any other way to do it. Once it counts to one if the person clicks on another checkbox i want it to go to 2.

<script>
var totalChecked=0
function countCheckboxes(clickedBox){
if(clickedBox.checked)
totalChecked=totalChecked+1

else
totalChecked=totalChecked-1

}
</script>
<form>
<input type="checkbox" id="box1" onClick="countCheckboxes(this)">
<input type="checkbox" id="box2" onClick="countCheckboxes(this)">
</form>
<script>
document.write("score "+totalChecked)
</script>

This is what i tried and it looks like it would work but when i check a check box the score does not change from 0 to 1.

Spudhead
07-15-2003, 05:27 PM
var totalChecked=0
function countCheckboxes(clickedBox){
if(clickedBox.checked){
totalChecked=totalChecked+1
}
else{
totalChecked=totalChecked-1
}
}


<input type="checkbox" id="box1" onClick="countCheckboxes(this)">


Something like that should work? Obviously if you've got boxes that are checked by default on page load, your var totalChecked needs to be initialised to reflect this.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum