Once my client asked me to do a validation for a form in which contains many check boxes. The form can submit the data if and only if at most 'm' number of check boxes are clicked. I have written a javascript function for that, so that it can re-use.
code:
function checkboxValidate(cform,max)
{
+++for (var c=0,d=0,e; e=cform[d]; d++)
++++{
+++++if (e.type=='checkbox' && e.name.match(/^show\[\]$/) && e.checked)
+++++++c++;
++++}
+++if (c > max)
+++{
++++alert('You can only click m checkboxes ');
+++++return false;
++++}
+++return true;
}
the function checkboxValidate takes two arguments
a. cform - the name of the form, in which contains the checkboxes
b. max - the allowed maximum number of checks.
You can edit this function and can enable it for the use of at least m number of clicks, that I left to you.
0 Response to "check box validation"
Post a Comment