Javascript: A simple way when validating forms to ensure at least one checkbox is checked

Check so at least one checkbox on your form is checked before it’s allowed to submit:

$("#main_form").on('submit',function(e){

   if ( $("input[type='checkbox']:checked").length > 0) {

   }
   else {
         e.preventDefault();

         alert("Please check at least one list you wish to be included in.");
         return false;
   }

   return true;

});

 

About Author:

Senior Cloud Software Engineer and 25+ years experienced video production, video editing and 3D animation services for a variety of global clients including local video production here in Jacksonville, Florida.

Leave a Comment

Your email address will not be published. Required fields are marked *