title: Select dropdown value in jquery based on value from db
body: <p>I have a HTML dropdown list with single selection. I want to select a value according to an value which I get from the database.</p>
  
  <pre><code>&lt;select name="aa"&gt;
      &lt;option&gt;BE&lt;/option&gt;
      &lt;option&gt;TE&lt;/option&gt;
      &lt;option&gt;SE&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>I get the value "TE" from the db and then I tried these 3 ways of setting the associated option tag selected.</p>
  
  <pre><code>if($m_aa == "TE"){
  $script = &lt;&lt;&lt; EOF
  &lt;script type='text/javascript'&gt;
      jQuery(document).ready(function($) {
          // $('#aa option:contains("' + BE + '")').attr('selected', 'selected'); //won't work
          // $('#aa option:eq(0)').attr('selected', 'selected'); //won't work
          $('#aa option:eq(1)').prop('selected', true); //won't work
       });
  &lt;/script&gt;
  EOF;
  echo $script;
  }
  ....
  
  &lt;dropdown list&gt;
  </code></pre>
  
  <p>But none of the 3 possibilities will work.
  Firebug don't show any error, if I add an alert(); it will shown. So syntactically it should be fine. I use jquery version 1.8.6 within a wordpress plugin in which this functionality I mentioned above should be implemented.</p>
  
  <p>BR,
  mybecks</p>