Get the selected value from a select box


/ Published in: jQuery
Save to your folder(s)

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).


Copy this code and paste it in your HTML
  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>

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.