title: Pass all checkboxes values as an array in Javascript
body: <p>I have the below checkboxes and I need to get them as an array values.</p>
  
  <pre><code>&lt;input type="checkbox" id="contact_id" value="4" /&gt;
  &lt;input type="checkbox" id="contact_id" value="3" /&gt;
  &lt;input type="checkbox" id="contact_id" value="1" /&gt;
  &lt;input type="checkbox" id="contact_id" value="5" /&gt;
  </code></pre>
  
  <p>I need to pass them to one ajax request as array as below:</p>
  
  <pre><code>xmlHttp.open("POST","?action=contact&amp;contact_id=" +contacts,true);
  </code></pre>
  
  <p>I am using this function to get the values but not able to pass them to the function as array, the passed like this <code>4,3,1,5.</code> I need them to be passed like this </p>
  
  <p><code>contact_id[]=4&amp;contact_id[]=3&amp;contact_id[]=1&amp;contact_id[]=5</code></p>
  
  <p>I have done this as follows </p>
  
  <pre><code>function getContacts(){
              var contacts = document.myform.contact_id, ids = [];
              for (var i = 0; i &lt; contacts.length; i += 1){
                  if (contacts[i].checked)
                       ids.push(contacts[i].value);
              }
              return ids;
          }
  </code></pre>