user951042
user951042

Reputation:

Getting the selected option with jquery

I have this;

<select id='list'>
    <option value='1'>First</option>
    <option value='2'>Second </option>
    <option value='3'>Third </option>
</select> 

i want to specifically get the option selected and put it an a variable, then alert what's in the variable.
I tried

var value = $("#list option:selected").text();
alert(value);

but its not working :(
Ps: i need the selected value in a variable. Thanks

Upvotes: 0

Views: 124

Answers (1)

erimerturk
erimerturk

Reputation: 4288

$('#list').change(function() {
  var value = $("#list option:selected").text();
alert(value);
});

http://jsfiddle.net/8Y9WT/

Upvotes: 1

Related Questions