By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,627 Members | 1,682 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,627 IT Pros & Developers. It's quick & easy.

How do I check for multple selection of CHECKBOX?

P: n/a
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.
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Fendi Baba" <ef*****@epitome.com.sg> wrote in message
news:c9**************************@posting.google.c om...
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[i].type == "checkbox") {
if (form.elements[i].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>
Jul 23 '05 #2

P: n/a
Fendi Baba wrote:
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.

--
Lachlan Hunt
http://lachy.id.au/
http://GetFirefox.com/ Rediscover the Web
http://GetThunderbird.com/ Reclaim your Inbox
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.