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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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