Selecting an option value with Javascript, using PHP
<p>Ok, so here is my code. I am trying to select a picklist value using Javascript, from PHP (I do not want a direct method to do this with PHP, as this won't work for my particular program)</p>

<p>Here's the code:</p>

<pre><code>ECHO '&lt;script type="text/javascript"&gt;
    var pl = document.getElementById("cultpicklist");
 pl.options[37].selected = true;
 &lt;/script&gt;';
</code></pre>

<p>However when I try to run this, it does not seem to work and it says pl.options[37] is undefined.</p>

<p>What am I doing wrong?</p>

<p>Note, there is a multiple select list which has an option with a value of 37.</p>

<p>EDIT: I seem to get this error or warning message:</p>

<pre><code>Element referenced by ID/NAME in the global scope. Use W3C standard document.getElementById() instead.
admin.php?org=7()admin.php?org=7 (line 68)
pl.options[37].selected = true;
</code></pre>

<p>Here's the relevant HTML:</p>

<pre><code>&lt;fieldset&gt;&lt;label for="culture"&gt;Culture:&lt;/label&gt;
        &lt;select name="culture[]" multiple="multiple" id="cultpicklist"&gt;&lt;?php
    while ($cultrow = mysql_fetch_array($rescult)) {
        ECHO '&lt;option name="culture[]" value="'. stripslashes($cultrow['cult_id']) .'"&gt;'. stripslashes($cultrow['cult_desc']) .'&lt;/option&gt;';
    }
    ?&gt;
        &lt;/select&gt;&lt;/fieldset&gt;
</code></pre>

<p>Here's the generated HTML code:</p>

<pre><code>&lt;select id="cultpicklist" multiple="multiple" name="culture[]"&gt;
&lt;option value="36" name="culture[]"&gt;test1&lt;/option&gt;
&lt;option value="37" name="culture[]"&gt;test2&lt;/option&gt;
&lt;option value="38" name="culture[]"&gt;test3&lt;/option&gt;
&lt;option value="39" name="culture[]"&gt;test4&lt;/option&gt;
&lt;/select&gt;
</code></pre>
