Getting the value of multiple selected options

var foo = [];  
$('#multiple :selected').each(function(i, selected){
  foo[i] = $(selected).text();
});
// to get the selected values, just use .val() - this returns a string or array
foo = $('#multiple :selected').val();  

Download this snippet

We’re using jQuery’s “each()” method to loop through all selected options in a multiple select list. Each value or text value is read into an array for later use.

Twitter Twitter

3 Comments to “ Getting the value of multiple selected options”

  1. Anonymous  on Sep 25, 2009

    PLpkaK <a href="http://mjyzetjekoyy.com/">mjyzetjekoyy</a>, [url=http://kqogmwmlplou.com/]kqogmwmlplou[/url], [link=http://bmcgudxipfgr.com/]bmcgudxipfgr[/link], http://whddhlfzlcuj.com/

  2. Anonymous  on Feb 21, 2010

    f3HWbG <a href="http://vjqkzovdizib.com/">vjqkzovdizib</a>, [url=http://dqhxxguvtjew.com/]dqhxxguvtjew[/url], [link=http://qmigiieqqpcz.com/]qmigiieqqpcz[/link], http://wulxrxeboyqa.com/

  3. Anonymous  on Mar 14, 2010

    6i5Y16 <a href="http://pavahuywaoyh.com/">pavahuywaoyh</a>, [url=http://pfggtcpwotdx.com/]pfggtcpwotdx[/url], [link=http://egxolnzknyum.com/]egxolnzknyum[/link], http://hvdarnixgnrd.com/

Leave a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>