Select a Multi-select DropDown by values with jquery
<p>I have asked a similar <a href="http://stackoverflow.com/questions/12584387/select-a-dropdown-by-values-with-jquery">question</a> this morning, how to select a dropdown by its value rather than sequence.</p>

<p>The problem is now how to use a multi-select dropdown and select the options by their value rather than sequence. (e.g. I would like to select a1 and a3, by their respective primary key, 1 and 4) </p>

<pre><code>&lt;select id="id_deals-sales_item" multiple="multiple"&gt;
  &lt;option value="1"&gt;a1&lt;/option&gt;
  &lt;option value="2"&gt;a2&lt;/option&gt;
  &lt;option value="4"&gt;a3&lt;/option&gt;
&lt;/select&gt;
</code></pre>

<p>The old way by sequence:</p>

<pre><code>for (i=0; i&lt;data[0].fields['sales_item'].length;i++)
    $('#id_deals-sales_item&gt;option:eq(' + (data[0].fields['sales_item'][i]) + ')').prop('selected', true);
</code></pre>

<p>I was hoping to apply the same solution here with val(), But it doesn't work.</p>

<pre><code>for (i=0; i&lt;=data[0].fields['sales_item'].length;i++)
    $('#id_deals-sales_item').val(data[0].fields['sales_item'][i]); 
</code></pre>

<p>Do I have to apply a different trick here? Thanks</p>
