title: javascript require a checkbox to be checked from an array of checkboxes
body: <p>I currenlty have some javascript/jquery code that displays an error message if no boxes are checked. However when I check a box and submit the form the error message still displays.</p>
  
  <p>any help would be great!</p>
  
  <p><strong>javascript code</strong>:</p>
  
  <pre><code>    var hobbies = $('#hobbies').val();
      if ($('#hobbies :checkbox:checked').length === 0){
      $("#multichk").after('&lt;span class="error"&gt;Please choose at least one.&lt;/span&gt;');
      hasError = true;
      }
  </code></pre>
  
  <p><strong>html code:</strong></p>
  
  <pre><code> &lt;input type='checkbox' id='hobbies' name='hobbies[0]' value='1'/&gt;&lt;label for='hobbies0'&gt;football&lt;/label&gt;&lt;br /&gt;
  
   &lt;input type='checkbox' id='hobbies' name='hobbies[1]' value='2'/&gt;&lt;label for='hobbies1'&gt;soccer&lt;/label&gt;&lt;br /&gt;
  
   &lt;input type='checkbox' id='hobbies' name='hobbies[2]' value='3'/&gt;&lt;label for='hobbies2'&gt;baseball&lt;/label&gt;&lt;br /&gt;
  
   &lt;input type='checkbox' id='hobbies' name='hobbies[3]' value='4'/&gt;&lt;label for='hobbies3'&gt;tennis&lt;/label&gt;&lt;br /&gt;
  
   &lt;input type='hidden' id='multichk' /&gt;
  </code></pre>
  
  <p>Thank you.</p>