PyraX Posted January 9, 2008 Share Posted January 9, 2008 Hi, does anyone have a script to validate there are at least 5 checkboxes selected. the checkboxes name is checkbox[] if that makes a difference. Thanks PyraX Quote Link to comment Share on other sites More sharing options...
jos. Posted January 10, 2008 Share Posted January 10, 2008 <script type="text/javascript"> function check_box_count(the_form_name){ var the_form = document.getElementByName('the_form_name'); //get the form object by the name assign it to the the_form var var count = 0; initialize the count var for(i=0;i<the_form.length;i++){ // this loops through the elements in the form if(the_form.elements[i].type == 'checkbox'){ // if the element is one of the check boxes proceed if(the_form.elements[i].checked == true){ // if the check box is checked then increase the count count++; } } } if(count == 5 ){ return true; }else{ return false; } } </script> <!-- in the HTML form tag --> <form name="your_form" method="post" action="yourScript.php" onSubmit="check_box_count(this.name)"> <!-- calling on the submit action --> </form> This should do it. Jos. Quote Link to comment Share on other sites More sharing options...
PyraX Posted January 17, 2008 Author Share Posted January 17, 2008 this doesnt seem to work. I know its initiating the function check_box_count but that it Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.