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.
<select name="aa">
<option>BE</option>
<option>TE</option>
<option>SE</option>
</select>
I get the value "TE" from the db and then I tried these 3 ways of setting the associated option tag selected.
if($m_aa == "TE"){
$script = <<< EOF
<script type='text/javascript'>
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
});
</script>
EOF;
echo $script;
}
....
<dropdown list>
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.
BR, mybecks