Reputation: 480
I have a select list with the following markup:
<select name="dropdown[users]">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">2</option>
</select>
I want to get the value of the select list option.
how is this done is jQuery?
I have tried:
$('select[name="dropdown[users]"]');
This doesn't seem to work
Any ideas?
Upvotes: 4
Views: 4320
Reputation: 3393
to obtain the value you must use the .val() method
$('select[name="dropdown[users]"]').change(function(){
alert($(this).val());
});
Upvotes: 0
Reputation: 337560
Use val()
:
var selectValue = $('select[name="dropdown[users]"]').val();
The fact the name has []
in it is not a factor as you have enclosed the attribute value in quotes.
If you removed the quotes, you would need to escape the braces with \\
, like this:
var selectValue = $('select[name=dropdown\\[users\\]]').val();
Upvotes: 7