Ok, what am I doing wrong here? I want to count the checkbox and increment, if you uncheck, it should decrement.
My checkboxes are in a form named: form2
The checkboxes are named: checkbox
Code:
function checkbox_stat() {
if(document.form2.checkbox.checked == true) ++document.getElementById('select_chks').innerHTML;
else --document.getElementById('select_chks').innerHTML;
}
I have a SPAN ID called: select_chks that displays the number of checkboxes selected.
And when you click on a checkbox, it calls the function above:
onClick="checkbox_stat(this);"
What I am getting is negative numbers like -1, -2, -3...
Which means that the first conditional isn't working and it's resorting to the else condition....which of course, decrements...
But why is this not working?
if(document.form2.checkbox.checked == true)