title: Looping through checkboxes in javascript
body: <p>I feel like I should know the answer but I just can't get it. I have a big form and some questions have checkboxes. I need to be able to loop through each of the checkboxes for that particular question and for the ones that're checked, I need to store in an array. I'm forced to use javascript due to working with existing code. here's one example I've tried:</p>
  
  <pre><code>&lt;input type="checkbox" name="CAT_Custom_15" id="CAT_Custom_15_0" value="Bareboat charters"&gt;
  &lt;input type="checkbox" name="CAT_Custom_15" id="CAT_Custom_15_1" value="charters"&gt;
  &lt;input type="checkbox" name="CAT_Custom_15" id="CAT_Custom_15_2" value="Ferry"&gt;
  
  &lt;script&gt;
  var theForm = document.getElementById( 'OMRForm' );
  var i;
  var selectArray = []; //initialise empty array
  for (i = 0; i &lt; theForm.CAT_Custom_15.length; i++) {
      if(theForm.CAT_Custom_15.elements[i].type == 'checkbox'){
           if(theForm.CAT_Custom_15.elements[i].checked == true){
              selectArray.push(theForm.CAT_Custom_15.elements[i].value);
              alert(theForm.CAT_Custom_15.elements[i].value);
           }
       }
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>I've stared at this so long it that I'm sure i've made a mistake somewhere. Please help!</p>