title: Validate checkbox in jquery
body: <p>I have a PHP form where atleast one checkbox be selected before submitting the form. If submit is clicked without selecting atleast one checkbox, it
  needs an alert. Could anyone suggest me doing this in Jquery1.10.2. I tried my best in jquery, its working for me.</p>
  
  <pre><code>&lt;script&gt;
  function onSubmit() 
  { 
    var fields = $(".chk_boxes1").serializeArray(); 
    if (fields.length == 0) 
    { 
      alert('nothing selected'); 
      // cancel submit
      return false;
    }   
  }
  // register event on form, not submit button
  $('#subscribeForm').submit(onSubmit)
  &lt;/script&gt;
  
  
  &lt;?php
  echo '&lt;form action="" method="post" id="subscribeForm"&gt;               
         &lt;table&gt;
           &lt;tr&gt;                                              
              &lt;th&gt;ROLE&lt;/th&gt;
              &lt;th&gt;DESCRIPTION&lt;/th&gt;    
              &lt;th&gt;PERMISSIONS&lt;br&gt;&lt;input type="checkbox" class="chk_boxes"&gt;&lt;/th&gt;  
           &lt;/tr&gt;
  
           &lt;tr&gt;
              &lt;td&gt;&lt;input type="text" name="role_name" required&gt;&lt;/td&gt;
              &lt;td&gt;&lt;input type="text" value="" name="role_desc" required&gt;&lt;/td&gt;
              &lt;td&gt;&lt;input type="checkbox" class="chk_boxes1" name="perm[]" value="0"&gt;My Account&lt;br&gt;
                  &lt;input type="checkbox" class="chk_boxes1" name="perm[]" value="1"&gt;Edit Account&lt;br&gt;
                  &lt;input type="checkbox" class="chk_boxes1" name="perm[]" value="2"&gt;Change password&lt;br&gt;
                  &lt;input type="checkbox" class="chk_boxes1" name="perm[]" value="3"&gt;List of users&lt;br&gt;
                  &lt;input type="checkbox" class="chk_boxes1" name="perm[]" value="4"&gt;Define roles&lt;br&gt;
                  &lt;input type="checkbox" class="chk_boxes1" name="perm[]" value="5"&gt;Assign roles&lt;br&gt;
           &lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
           &lt;div&gt;&lt;input type="submit" name="new_role" value="create newrole"&gt;&lt;/div&gt;
        &lt;/form&gt;';
  ?&gt;
  </code></pre>