title: Pass jQuery array value on submit as hidden input
body: <p>On button press the following code will display a message with values collected from all checkboxes. But I want to pass these values (returned by function) as hidden input on submit.</p>
  
  <pre><code>&lt;form action="script.php" method="post"&gt;
  &lt;input type="checkbox" name="chb1" value="html" /&gt;HTML&lt;br/&gt;
  &lt;input type="checkbox" name="chb2" value="css" /&gt;CSS&lt;br/&gt;
  &lt;input type="checkbox" name="chb3" value="javascript" /&gt;JavaScript&lt;br/&gt;
  &lt;input type="checkbox" name="chb4" value="php" /&gt;php&lt;br/&gt;
  &lt;input type="checkbox" name="chb5" value="python" /&gt;Python&lt;br/&gt;
  &lt;input type="checkbox" name="chb6" value="net" /&gt;Net&lt;br/&gt;
  &lt;input type="button" value="Click" id="btntest" /&gt;
  &lt;/form&gt;
  
  &lt;script type="text/javascript"&gt;&lt;!--
  function getSelectedChbox(frm) {
    var selchbox = [];        
    var inpfields = frm.getElementsByTagName('input');
    var nr_inpfields = inpfields.length;
     for(var i=0; i&lt;nr_inpfields; i++) {
      if(inpfields[i].type == 'checkbox' &amp;&amp; inpfields[i].checked == true) selchbox.push(inpfields[i].value);
    }
    return selchbox;
  }
  
  
  document.getElementById('btntest').onclick = function(){
    var selchb = getSelectedChbox(this.form);   
    alert(selchb);
  }
  //--&gt;
  
  &lt;/script&gt;
  </code></pre>