title: Put checkbox values into hidden input with jQuery
body: <p>I'd like to populate a hidden input with the values of selected checkboxes with a space between these values. I've tried the following which in theory should work but it isnt…</p>
  
  <p>JS:</p>
  
  <pre><code>$(document).ready(function () {
  
  
        var vals = $(':checkbox:checked').map(function(){
           return $(this).val();
        }).get().join(',');
  
        // save the values to a hidden field
        $('#tags').val(vals);
  
  
  });
  </code></pre>
  
  <p>HTML</p>
  
  <pre><code> &lt;form&gt;
  
    &lt;input type="checkbox" value="test1" id="test1"&gt;&lt;label&gt;Test&lt;/label&gt;
    &lt;input type="checkbox" value="test2" id="test2"&gt;&lt;label&gt;Test2&lt;/label&gt;
    &lt;input type="checkbox" value="test3" id="test3"&gt;&lt;label&gt;Test3&lt;/label&gt;
  
    &lt;input type="text" value="" id="tags"&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p>Any ideas?</p>