Well, I have a form with dynamic checkboxes.
Before the user submits I want javascript to
check that at least one checkbox has been checked.
So far I havn't figured out a way to do this....
Here's some psudo-code that I've been working on...
<script type="text/javascript">
function valid()
{
var i;
var isValid = false;
for (i = 0; i < document.the_form.checkbox.length; i++) {
if(document.the_form.checkboxїi].checked == true) {
isValid = true;
}
}
if (!isValid) {
alert("You must select at least one option to continue.");
return false;
}
}
</script>
Note that for this to work I had to change the checkbox name to "checkbox" rather than "checkbox[]". I could not get this to work with "checkbox[]" as I think JavaScript then interprets it as a 2D array.