jQuery get checked checkboxes from name[]

javascript, jquery

Solution

First, you can get the checkboxes by `name`:

var checkboxes = $('input[name="price[]"]');

Then, to get the values of the `checked` ones, you can filter by the pseudo selector `:checked`, and then collect their `value`s:

checkboxes.filter(":checked").map(function () {
    return this.value;
}).get()

DEMO: http://jsfiddle.net/Fn9WV/

References:

- `jQuery().filter()` - http://api.jquery.com/filter/

- `jQuery().map()` - http://api.jquery.com/map/

Problem

I have checkboxes like so: ``` <ul id="searchFilter"> <li><input type="checkbox" name="price[]" class="cb_price" value="1"> $200,000 to $299,999</li> <li><input type="checkbox" name="price[]" class="cb_price" value="3"> $300,000 to $399,999</li> <li><input type="checkbox" name="price[]" class="cb_price" value="5"> $400,000 to $499,999</li> <li><input type="checkbox" name="price[]" class="cb_price" value="8"> $500,000+</li> </ul> ``` How would I alert the price[] to see what is checked? I am very new at jquery :(

Original source

Related problems