title: jQuery: Verify If one of multiple required checkboxes is/are checked
body: <p>I have a form with multiple groups of checkboxes (among other things). Some of these groups are mandatory fields (At least one checkbox needs to be checked within that group).</p>
  
  <p>I am able to tell if a group has a checkbox checked, but I failed to make them mandatory. Also I am need to get one long string with the values of the selected checkbox(es). I would need to have a string where if the user checks, say the first 3 checkboxes from group1, the string to be:
  <br/>
  "zero | 1 val | 2 val"</p>
  
  <p>The code is a simplified version of my original. Here is the jFiddle: <a href="http://jsfiddle.net/QyY2P/1/" rel="nofollow">http://jsfiddle.net/QyY2P/1/</a></p>
  
  <p>Also, for your convenience I am also including the code here:</p>
  
  <p><strong>jQuery</strong>:</p>
  
  <pre><code>function countChecked() {
      //Group 1
      var n = $("#group1 input:checked").length;
      $("#count").text(n + (n &lt;= 1 ? " is" : " are") + " checked!");
      $("#group1 input:checked").each(function() {
          txt += ($(this).val() + " | ");
          $("#selection1").text(txt);
          alert($(this).val() + " | ");
      });
  
  
      //Group 2
      var n = $("#group2 input:checked").length;
      $("#count").text(n + (n &lt;= 1 ? " is" : " are") + " checked!");
      $("#group2 input:checked").each(function() {
          txt += ($(this).val() + " | ");
          $("#selection3").text(txt);
          alert($(this).val() + " | ");
      });
  }
  
  countChecked();
  $(":checkbox").click(countChecked);
  </code></pre>
  
  <p><strong>HTML</strong>:</p>
  
  <pre><code>&lt;form&gt;
    &lt;div id="group1"&gt;
      &lt;p&gt; *Please select a box (Mandatory)&lt;/p&gt;
      &lt;input type="checkbox" name="ckb_unit[]" value="zero" /&gt;
      &lt;input type="checkbox" name="ckb_unit[]" value="1 val" /&gt;
      &lt;input type="checkbox" name="ckb_unit[]" value="2 val" /&gt;
      &lt;input type="checkbox" name="ckb_unit[]" value="3 val" /&gt;
      &lt;input type="checkbox" name="ckb_unit[]" value="4 val" /&gt;
    &lt;/div&gt;
  
  
    &lt;div id="group2"&gt;
        &lt;p&gt;Please select a box&lt;/p&gt;
      &lt;input type="checkbox" name="ckb_unit[]" value="zero" /&gt;
      &lt;input type="checkbox" name="ckb_unit[]" value="A" /&gt;
      &lt;input type="checkbox" name="ckb_unit[]" value="B" /&gt;
      &lt;input type="checkbox" name="ckb_unit[]" value="C" /&gt;
      &lt;input type="checkbox" name="ckb_unit[]" value="D" /&gt;
    &lt;/div&gt;
  
    &lt;div id="group3"&gt;
      &lt;p&gt;*Please select a box (Mandatory)&lt;/p&gt;
      &lt;input type="checkbox" name="ckb_unit[]" value="zero" /&gt;
      &lt;input type="checkbox" name="ckb_unit[]" value="1 A" /&gt;
      &lt;input type="checkbox" name="ckb_unit[]" value="2 B" /&gt;
      &lt;input type="checkbox" name="ckb_unit[]" value="3 C" /&gt;
      &lt;input type="checkbox" name="ckb_unit[]" value="4 D" /&gt;
    &lt;/div&gt;
  &lt;/form&gt;
  
  &lt;!-- For debugging purposes --&gt;
  &lt;br/&gt;
  &lt;div id="count"&gt;&lt;/div&gt;
  &lt;div id="selection1"&gt;&lt;/div&gt;
  &lt;div id="selection3"&gt;&lt;/div&gt;
  </code></pre>
  
  
    
      
      
      
      
      
    
  
  
    
      
      
      
      
      
    
  
    
      
      
      
      
      
    
  
  
  
  
  
  
  <p>PS. I am a beginner, perhaps you noticed it by my not so elegant coding >_&lt;</p>