lundi 4 juillet 2016

Get a list of all checked checkboxes

I would like to figure out which checkboxes are checked and so I tried this code:

$('.feature input[type="checkbox"').serialize();

This is how my HTML looks like:

<div class="feature">
  <h2>Features</h2>
  <label><input class="custom_css" checked="" type="checkbox" name="feature[]"> Custom CSS (style.css)</label>
  <label><input class="custom_js" checked="" type="checkbox" name="feature[]"> Custom Javascript (script.js)</label>
  <label><input class="modernizr" type="checkbox" name="feature[]"> Modernizr</label>
  <label><input class="google_maps" type="checkbox" name="feature[]"> Google Maps</label>
  <label><input class="custom_api" type="checkbox" name="feature[]"> Custom API</label>
  <label><input class="font_awesome" type="checkbox" name="feature[]"> Font Awesome</label>
</div>

And this is the output that I get:

array(1) { ["var_sent_via_ajax"]=> string(67) "feature%5B%5D=on&feature%5B%5D=on&feature%5B%5D=on&feature%5B%5D=on" }

Now how can I know which of them has been checked? And what do the signs %5B%5D mean?




Aucun commentaire:

Enregistrer un commentaire