How do I check for multple selection of CHECKBOX?

F

Fendi Baba

Hi everyone

I wrote an application that generates HTML based on some database
record set. One of the HTML generated is a checkbox with
NAME=StudentID. This is to facilitate user to select this user for
further processing. This also means that ALL student have a checkbox
named StudentID. I do I ensure that only one checkbox is selected at
any time before the user proceed with the processing of the selected
student.
 
M

McKirahan

Fendi Baba said:
Hi everyone

I wrote an application that generates HTML based on some database
record set. One of the HTML generated is a checkbox with
NAME=StudentID. This is to facilitate user to select this user for
further processing. This also means that ALL student have a checkbox
named StudentID. I do I ensure that only one checkbox is selected at
any time before the user proceed with the processing of the selected
student.

Will this help? Watch for word-wrap.

<html>
<head>
<title>boxcheck.htm</title>
<script type="text/javascript">
function boxcheck() {
var boxs = 0;
var form = document.forms[0];
for (var i=0; i<form.elements.length; i++) {
if (form.elements.type == "checkbox") {
if (form.elements.checked) boxs++;
}
}
if (boxs != 1) alert("Check one and only one box.");
}
</script>
</head>
<body>
<form action="" method="get">
<input type="checkbox" name="StudentID" value="1">
<input type="checkbox" name="StudentID" value="2">
<input type="checkbox" name="StudentID" value="3">
<input type="button" value="Click" onclick="boxcheck()">
<input type="reset" value="Clear">
</form>
</body>
</html>
 
L

Lachlan Hunt

Fendi said:
I do I ensure that only one checkbox is selected at
any time before the user proceed with the processing of the selected
student.

Why don't you use radio buttons for that purpose instead? No
client-side scripting would be involved (only server side validation
would still be necessary), and they are designed, so that only one radio
button per group can be selected.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top