How to set multiple select values from string using Jquery
<p>I have a span Id with some values that correspond to values in multiple select box items. I want to take the values from span Id and select the corresponding items in list. </p>

<pre><code>&lt;span id="test"&gt;
  1,4
&lt;/span&gt;
&lt;select id='multipleSelect' multiple='multiple'&gt;
  &lt;option value="1"&gt;1&lt;/option&gt;
  &lt;option value="2"&gt;2&lt;/option&gt;
  &lt;option value="3"&gt;3&lt;/option&gt;
  &lt;option value="4"&gt;4&lt;/option&gt;
  &lt;option value="5"&gt;5&lt;/option&gt;
&lt;/select&gt;
</code></pre>

<p>I can read the string into array but not sure how to use array to select items in multiple Select box</p>

<pre><code>var test = $("#test").text();
var testArray = test.split(',');
</code></pre>

<p>I guess if the values are known then it is easy to do something like this </p>

<pre><code>$('#multipleSelect').val(['1', '2']);
</code></pre>

<p>Here is JS fiddle to illustrate the idea so far
<a href="https://jsfiddle.net/deu8ftpb/1/" rel="nofollow">https://jsfiddle.net/deu8ftpb/1/</a></p>