title: Get html checkbox list checked values to a hidden field
body: <p>How to get the checked checkboxes id in to a hidden variable?</p>
  
  <p>I am getting this error. </p>
  
  <pre><code>SyntaxError: unterminated string literal
  
  var test = $('input[name=\'data-grid_c0[]\').val();
  </code></pre>
  
  <p><strong>data-grid_c0</strong> is the name of the checkbox array.</p>
  
  <pre><code>&lt;input type="checkbox" name="data-grid_c0[]" id="data-grid_c0_1" value="1"&gt;
  &lt;input type="checkbox" name="data-grid_c0[]" id="data-grid_c0_2" value="1"&gt;
  &lt;input type="checkbox" name="data-grid_c0[]" id="data-grid_c0_3" value="1"&gt;
  </code></pre>
  
  <p>Below is the jquery code i have written.</p>
  
  <pre><code>$('#deleteall-button').click(function () {
     var atLeastOneIsChecked = $('input[name=\"data-grid_c0[]\"]:checked').length &gt; 0;
     var test = $('input[name=\'data-grid_c0[]\').val();
  
     alert(test);
     if (!atLeastOneIsChecked)
     {
       alert('Please select atleast one record to delete');
     }
     else if (window.confirm('Are you sure you want to delete the records?'))
     {
       document.getElementById('search-form').action = 'index.php?r=device/bulkDelete';
       document.getElementById('search-form').submit();
     }
  });
  </code></pre>
  
  <p>I want the value of <strong>data-grid_c0</strong> to be assigned to <strong>selectedDevices</strong> hidden field.</p>
  
  <pre><code>&lt;form action="hotelSearch/hotelSearch" method="post"&gt;&lt;input id="selectedDevices" type="hidden" value="" name="selectedDevices" /&gt;&lt;a id="deleteall-button" class="btn btn-primary"&gt;Bulk Delete&lt;/a&gt;&lt;/form&gt;
  </code></pre>
  
  <p>So with php i will be able to handle it as following and delete, </p>
  
  <pre><code>//check-boxes
  if (isset($_POST['selectedDevices'])) { //data-grid_c0
      $del_camps = $_POST['selectedDevices']; //data-grid_c0
      $model_camp = new Device;
      foreach ($del_camps as $_camp_id) {
          $model_camp-&gt;deleteByPk($_camp_id);
      }
  }
  </code></pre>