tags:

views:

45

answers:

3

Does anyone know how can I get all values in the select by Jquery?

Example:

<select name="group_select" id="group_select">
    <option value="a">A</option>
    <option value="b">B</option>
    <option value="c">C</option>
</select>

Which I want to get all option values (a,b and c) from select (without selected any option) by using jquery

+1  A: 
var values = $("#group_select>option").map(function() { return $(this).val(); });
eulerfx
+1  A: 

The following will give you an array of the <option> values

var values = $.map($('#group_select option'), function(e) { return e.value; });

// as a comma separated string
values.join(',');

Here's a Working Demo. add /edit to the URL to see the code.

Russ Cam
A: 

This will iterate through all the options and give you their values. then you can either append them to an array, or manipulate them individually.

$('#group_select option').each(function(){
    $(this).val()
}
contagious