How to get the value of a selected option from a drop-down menu using jquery?

advertisements
  <select id="testSelection">
           <option> test1 </option>
           <option> test2 </option>
           <option> test3 </option>
           <option> test4 </option> <--- selected this one from the pull down menu
           <option> test5 </option>
           <option> test6 </option>
  </select>

             $("#testSelection").change(function()
             {
                    alert($(this).text());
             });

Strange to me, the alert message shows all the selections but I was expecting it to show on only test4 text.


<select id="testSelection">
    <option value="1">test1</option>
    <option value="2">test2</option>
    .....
</select>

It really depends on what you want:

$("#testSelection").on('change', function() {
    // if you just want the text/html inside the select (ie: test1, test2, etc)
    alert($(this).find('option:selected').text()); 

    // or you want the actual value of the option <option value="THISHERE">
    alert($(this).val());
});​

jsFiddle DEMO