title: Getting multiple selected checkbox values in a string in javascript and PHP
body: <p>I have location name and location Id in database table. Using foreach loop i'm printing the values in checkbox in PHP. I have a submit button which triggers a javascript. I want the user selected all checkbox values separated by comma, in a javascript variable. How can I do this?</p>
  
  <pre><code>    &lt;!-- Javascript --&gt;
  &lt;script&gt;
          function getLoc(){
                  var all_location_id = document.getElementByName("location[]").value;
                       var str = &lt;!-- Here I want the selected checkbox values, eg: 1, 4, 6 --&gt;
  
              }
          &lt;script&gt;
  
  foreach($cityrows as $cityrow){
  echo '&lt;input type="checkbox" name="location[]" value="'.$cityrow['location_id'].'" /&gt;'.$cityrow['location'];
  echo '&lt;br&gt;';
  }
  echo '&lt;input name="searchDonor" type="button" class="button" value="Search Donor" onclick="getLoc()" /&gt;';
  </code></pre>