title: jquery / php select multiple selected options from php array in jquery
body: <p>I'm trying to produce a multiple select list with selected options based from a php array, in jquery. I can't seem to get it working, this is my code:</p>
  
  <p>My select list:</p>
  
  <pre><code>&lt;select name="modules[]" id="modules" class="inputbox" size="10" multiple="multiple"&gt;
    &lt;option value="1"&gt;Module 01&lt;/option&gt;
    &lt;option value="2"&gt;Module 02&lt;/option&gt;
    &lt;option value="3"&gt;Module 03&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>My PHP/JQuery (attempt):</p>
  
  <pre><code>&lt;script type="text/javascript" language="javascript"&gt;
  &lt;?php 
  $modules = explode(';',$row-&gt;modules);
  if (is_array($modules)) {
      foreach($modules as $moduleID) { 
      ?&gt;
      jQuery("#modules").val("&lt;?php echo $moduleID; ?&gt;");
      &lt;?php 
      };
  } else { 
  ?&gt;
  jQuery("#modules").val("&lt;?php echo $row-&gt;modules; ?&gt;");
  &lt;?php 
  };
  ?&gt;
  &lt;/script&gt;
  </code></pre>
  
  <p>Which looks like (plain jquery):</p>
  
  <pre><code>&lt;script type="text/javascript" language="javascript"&gt;
    jQuery("#modules").val("3");
    jQuery("#modules").val("1");
  &lt;/script&gt;
  </code></pre>
  
  <p>And this is my php array (after being exploded):</p>
  
  <pre><code>Array
  (
      [0] =&gt; 3
      [1] =&gt; 1
  )
  </code></pre>