Posted By

cyberhobo on 08/28/09


Tagged

select selectedIndex val selected-value


Versions (?)

Who likes this?

6 people have marked this snippet as a favorite

vali29
legacye
NyX
vagrantradio
vehler
fenta23


Get the selected value from a select box


 / Published in: jQuery
 

URL: http://docs.jquery.com/Val

It's not obvious from the jQuery documentation that val() will work to get the currently selected value of a select box (in 1.3.2 at least).

  1. <select id="test-select">
  2. <option value="1" selected="selected">One</option>
  3. <option value="2">Two</option>
  4. <option value="3">Three</option>
  5. </select>
  6.  
  7. <p>Selected value: <span id="selected-value"></span></p>
  8.  
  9. <script type="text/javascript">
  10.  
  11. jQuery( '#selected-value' ).text( jQuery( '#test-select' ).val() ); // 1
  12.  
  13. </script>

Report this snippet  

You need to login to post a comment.