Return to Snippet

Revision: 17247
at August 31, 2009 17:16 by cyberhobo


Updated Code
<select id="test-select">
<option value="1" selected="selected">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>

<p>Selected value: <span id="selected-value"></span></p>

<script type="text/javascript">

jQuery( '#selected-value' ).text( jQuery( '#test-select' ).val() ); // 1

</script>

Revision: 17246
at August 28, 2009 08:44 by cyberhobo


Initial Code
<select id="test-select">
<option value="1" selected="selected">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>

<p>Selected value: <span id="selected-value"></span></p>

<script type="text/javascript">

jQuery( '#sected-value' ).text( jQuery( '#test-select' ).val() ); // 1

</script>

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

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

Initial Title
Get the selected value from a select box

Initial Tags


Initial Language
jQuery