javascript - JQuery Select All Option Values From DualListBox -


i'm using dual listbox plugin , trying select list of countries using jquery:

var countries = $('.selected').find(":selected").map(function(){ return this.value }).get().join(", "); 

this listbox:

<select class="selected" style="height: 200px; width: 100%;" multiple="" name="countries[]"> <option style="padding:4px 0px 4px 8px;" value="ca" selected="">canada</option> <option style="padding:4px 0px 4px 8px;" value="fr" selected="">france</option> <option style="padding:4px 0px 4px 8px;" value="de" selected="">germany</option> <option style="padding:4px 0px 4px 8px;" value="nl" selected="">netherlands</option> <option style="padding:4px 0px 4px 8px;" value="uk" selected="">united kingdom</option><option style="padding:4px 0px 4px 8px;" value="us" selected="">united states</option> </select> 

i'm trying comma separated list looks this:

ca, fr, de, nl, uk

how write jquery line correctly?

edit 1

var countries = $('.selected').find('option').each(function(){return $(this).val();}).get().join(", "); 

this produces:

[object htmloptionelement], [object htmloptionelement], [object htmloptionelement], [object htmloptionelement], [object htmloptionelement], [object htmloptionelement]

so think close?

try this:

var countries = $('.selected').find('option').map(function() { return this.value }).get().join(", "); 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -