Setting the selectedindex property of an HTML dropdown using PHP
<p>From the database I pull back the user information and based on this I can determine the correct index value using a case statement:</p>

<pre><code>&lt;?php
    $genderIndex = 0;
    switch ($displayProperties['gender']) 
    {
        case "":
            $genderIndex = 0;
            break;
        case "Male":
            $genderIndex = 1;
            break;
        case "Female":
            $genderIndex = 2;
            break;
        case "Other":
            $genderIndex = 3;
            break;
    }
 ?&gt;
</code></pre>

<p>On the form I have an HTML dropdown (select):</p>

<pre><code>&lt;select name="gender" selectedIndex="&lt;?php echo $genderIndex; ?&gt;"&gt;
    &lt;option value="0"&gt; &lt;/option&gt;
    &lt;option value="Male"&gt;Male&lt;/option&gt;
    &lt;option value="Female"&gt;Female&lt;/option&gt;
    &lt;option value="Other"&gt;Other&lt;/option&gt;
&lt;/select&gt;&lt;br/&gt;
</code></pre>

<p>The problem is it never works and always loads the page at <code>index=0</code> and I made sure to verify if <code>$genderIndex</code> actually has the expected value (it does).</p>

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