RE: [PHP] Checkbox related...
| From: | Ernest E Vogelsinger | Date: | Sun, 16 Feb 2003 20:14:42 +0000 |
| Subject: | RE: [PHP] Checkbox related... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-135773@lists.php.net to get a copy of this message | ||
At 20:34 16.02.2003, Dhaval Desai said:
--------------------[snip]--------------------
>How do we do it using the first option i.e javascript to count how many
>boxes are checked...could you give some example...
--------------------[snip]--------------------
Warning - untested:
<script language="JavaScript">
function validateChecks()
{
aboxes =
Array('box1','box2','box3','box4','box5');
hF = document.forms['myform'];
if (hF) {
for (i = 0, count=0; i < aboxes.length; i++) {
hBox = hF.elements[aboxes[i]];
if (hBox.checked) {
++count;
if (count >= 2)
return true;
}
}
}
return false;
}
</script>
----
<form name="myform" onSubmit="validateChecks()">
<input type="checkbox" name="box1" value="1">
<input type="checkbox" name="box2" value="1">
<input type="checkbox" name="box3" value="1">
<input type="checkbox" name="box4" value="1">
<input type="checkbox" name="box5" value="1">
<input type="submit">
</form>
----
I believe you get the idea...
--
>O Ernest E. Vogelsinger
(\) ICQ #13394035
^ http://www.vogelsinger.at/