Using jQuery, how can I store the selected values of a select into an array?
<p>Thanks for reading this.</p>

<p>I would have thought it would be as simple as using the .split function on the select .val(), but I get a js error. This is the code I am using. I will use .each() to loop through the selected items...but would like to understand what I am doing wrong...</p>

<p>If I set opts with a literal..the split works (commented code)</p>

<p>Thanks</p>

<pre><code>&lt;html&gt;&lt;head&gt;
&lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"&gt;&lt;/script&gt;
&lt;script type="text/JavaScript"&gt;
$(function(){
 $("#multOpts").bind("click", function() {
 // var opts = "OPT1,OPT2,OPT3" ;
  var opts = $("#select1").val() ;
  $("#text1").val(opts);
 });
 $("#oneOpt").bind("click", function() {
  // var opts = "OPT1,OPT2,OPT3" ;
  var opts = $("#select1").val() ;
  var optsArray = opts.split(",") ;
  $("#text2").val("1st opt: " + optsArray[0]);
 });
}); // End eventlistener
&lt;/script&gt;
&lt;/head&gt;&lt;body&gt;
&lt;select id="select1" multiple size="5"&gt;
&lt;option value="OPT1"&gt;Option 1&lt;/option&gt;
&lt;option value="OPT2"&gt;Option 2&lt;/option&gt;
&lt;option value="OPT3"&gt;Option 3&lt;/option&gt;
&lt;option value="OPT4"&gt;Option 4&lt;/option&gt;
&lt;option value="OPT5"&gt;Option 5&lt;/option&gt;
&lt;/select&gt;
&lt;div&gt;
&lt;input id="multOpts" type="button" value="Show Options"/&gt;
&lt;input id="text1" type="text"/&gt;
&lt;/div&gt;
&lt;input id="oneOpt" type="button" value="One Option"/&gt;
&lt;input id="text2"  type="text"/&gt;
&lt;/body&gt;&lt;/html&gt;
</code></pre>
