views:

224

answers:

2

Hello,

I have this :

<select id="CheckList" multiple="multiple">
  <option>1</option>
  <option>2</option>
  <option>3</option>
  <option>4</option>
</select>

Is it possible with jQuery to get a full list of the options with separator bewteen like this : 1,2,3,4

Thanks,

+1  A: 

Use map() and join() but you have to use get() on the map() result to convert it into a Javascript array (which has the join() method):

var list = $("#CheckList option").map(function(i, n) {
  return n.value;
}).get().join(",");
cletus
I have a syntax error (not a function)
Kris-I
A: 
var list = ''

$(#CheckList).children.each(function() { list += this.value + ',' }

accidentally posted this befoere finishing. meant to say something like this. But the guy above has the solution.

Damian