Get Values From Multiple Select With JQuery

jQuery makes it easy to get the value from a multiple-select. First the HTML code:

<select id="a-select" multiple="multiple">
    <option value="1">No 1</option>
    <option value="2">No 2</option>
    <option value="3">No 3</option>
    <option value="4">No 4</option>
    <option value="5">No 5</option>

The JavaScript to pull out the values is:

$('#my_select').change(function() {
    var v = ( $('#a-select :selected').val() || [] ), tVal = [];
    $('#a-select :selected').each(function(i, selected){ 
      tVal.push = $(selected).text(); 
    $("#output").html ( "The Selected Value are "+v+" with tags "+tVal );

•       •       •       •       •       •

Summary: # of Words: 104
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