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 Link to comment https://forums.phpfreaks.com/topic/85270-min-5-checkbox-validation/ 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. Link to comment https://forums.phpfreaks.com/topic/85270-min-5-checkbox-validation/#findComment-435182 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 Link to comment https://forums.phpfreaks.com/topic/85270-min-5-checkbox-validation/#findComment-441629 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.