"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>