I am trying to write some form validation code to check that at least one checkbox is checked when an HTML form is submitted.
The problem is that the number of check boxes is dynamically generated and so I do not know how many checkboxes there are. The variable name of each checkbox is dynamically created as follows:
rec_con_assign_1, rec_con_assign_2, rec_con_assign_3... and so on.
This is what I have written:
Code: Select all
var flag=0;
var counter=1;
while (rec_con_assign_[counter]){
if(form.rec_con_assign_[counter].checked){
flag++;
}
counter++;
}
if (flag == 0){
alert ("You must check one and only one checkbox!");
return false;
} Thanks in advance,
Rob.