ffffff01 ffffff01 - 4 months ago 30
jQuery Question

How to get all option values in a multiple select with jquery?

I'm trying to get all options values of a multiple select with the following code.

var service_m = $("#SelectRight>option").map(function () { return $(this).val(); });


When I do this I only get [object Object] in return.

Any suggestions on how to solve this?

Answer

Try:

var arr = [];
$("#SelectRight > option").each(function(){
   arr.push(this.value);
});

That will store all values in arr array.

If you want them to be a single string with comma separated, you can go further like this:

var str = arr.join(', ');