views:

52

answers:

1

How do I get the option's value that was selected in a dropdown list when a button is clicked?

<select id="d1"><option value="1">One</option>...</select>
+4  A: 
$('#btn').click(function () {
    var value = $('#d1').val();
})

$(element).val() returns the value of any form element.

Emil Ivanov
No, it IS correct. Try it. jQuery knows what it's doing.
Emil Ivanov
@Emil Pretty sure I have run into this numerous times, but I'll take your word, no time to try it.
meagar
Apologies, I was mistaken.
meagar
should that say "var value" not "val value"?
Chris F
`var` of course, my bad!
Emil Ivanov