Click to See Complete Forum and Search --> : How to Count Checkbox checked.


JohnJava
02-18-2004, 08:16 PM
Hi all, I want to know how to count how many checkboxes checked by user, the result will be processed in submit.asp and then timed with number 2. Lastly, the final result will be displayed to the user. I need the code in JavaScript. Please Help me....

<html>

<body>
<form action="submit.asp" name="submit" method="post">
<p><h3>Stage 1</h3>
<input type="checkbox" name="cb" value="ON"><br>
<input type="checkbox" name="cb" value="ON"><br>
<input type="checkbox" name="cb" value="ON"><br>
<input type="checkbox" name="cb" value="ON"><br>
<input type="checkbox" name="cb" value="ON"><br>
<input type="reset" name="cmdreset" value="Reset">
<input type="Submit" name="cmdsubmit" value="Submit">
</P>
</form>
</body>

</html>

PeOfEo
02-18-2004, 09:29 PM
check boxes output a boolean value, 1 and 0. So if you were to just add them all together you would see how many were checked.

buntine
02-18-2004, 11:29 PM
Only the checked boxes will be sent to the server for processing. The easiest way to get the amount of checked boxes on the server is as follows:


dim checkedBoxes

checkedboxes = CInt(UBound(Split(request.form("cb"), ",")))


This will cast the upperbound index of the 'cb' form element as an integer.