Jump to content

Min 5 checkbox validation


PyraX

Recommended Posts



<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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.