ffffff01 ffffff01 - 1 year ago 98
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 Source


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

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(', ');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download