Get Values From Select With JQuery

You can get the values that are selected in jQuery easily. First the HTML:

<select id="a-select">
    <option value="yes">Yes</option>
    <option value="no">No No</option>
</select>


The JavaScript is:

$('#my_select').change(function() {
    var v = $('#a-select :selected').val();
    var t = $( "#a-select option:selected" ).text();    
    $("#output").html ( "The Selected Value is["+v+"] with a tag of ["+t+"]" );
});



•       •       •       •       •       •

Summary: # of Words: 80
Author: Philip Schlump
Published On: 2013-05-05

Download code from this articles in .tar.gz for Mac/Linux/Unix or .zip with CR/LF for Windows format.

 

Before You Go....

Have you read "Unintend Consinsequences"?

"I laughed so hard it hurt..."
    Rod Brown

"Incredibly funny! Incredibly true!"
    Tad Stevens