title: How to pass multiple checkbox values into an array
body: <p>I am trying to pass values from a checkbox list when selected to a jquery function, so i can play around with the selected values. Below the code does not work</p>
  
  <p>I want to be able to use the value outside of the checkbox function </p>
  
  <p>So for example if i had another button outside that function it should be able to read what was stored into the array - The code below does not work for some reason, any help would be appreciated</p>
  
  <p>jquery   </p>
  
  <pre><code> &lt;script&gt;
      $(document).ready(function(){
  
      var vals = []
      $('input:checkbox[name="check[]"]').each(function() {
          if (this.checked) {
              vals.push(this.value);
          }
      });
  
       alert(vals[0]);
      });
      &lt;/script&gt;
  </code></pre>
  
  <p>HTML Code</p>
  
  <pre><code>&lt;form&gt;
  &lt;input value="BOOZE" type="checkbox" name="check[]" &gt;PUB, MATES, &lt;br&gt;
  &lt;input value="TV"  type="checkbox" name="check[]"&gt;BRIBING THE KIDS TO GO BED&lt;br&gt;
  &lt;input value="BOOZE" type="checkbox" name="check[]"&gt;RAVING TILL THE EARLY HOURS&lt;br&gt;
  &lt;input value="PETS"  type="checkbox" name="check[]"&gt;PLAYING GRAND THEFT AUTO &lt;br&gt;
  &lt;input value="GEEK"  type="checkbox" name="check[]"&gt;TWEETING ABOUT SOMETHING &lt;br&gt;
  &lt;input value="SPORT"  type="checkbox" name="check[]"&gt;GYM&lt;br&gt;
  &lt;input value="XMAS"  type="checkbox" name="check[]"&gt;SINGING CHRISTMAS SONGS&lt;br&gt;
  &lt;input type="checkbox" class="chkNumber" name="check[]"&gt;SHARING A DELIGHTFUL BOTTLE 
  &lt;/form&gt; 
  </code></pre>