Choosing Object in For Loop based on Input
<p>I want to populate select options based on the value of the previously selected option.</p>

<pre><code>            &lt;label for="state" class="block"&gt;State:*&lt;/label&gt;
            &lt;select name="state" id="state" tabindex="1"&gt;
                &lt;option value="Arizona"&gt;Arizona&lt;/option&gt;
                &lt;option value="Arkansas"&gt;Arkansas&lt;/option&gt;
                &lt;option value="Colorado"&gt;Colorado&lt;/option&gt;
            &lt;/select&gt;

            &lt;label for="location" class="block"&gt;Preferred Location:*&lt;/label&gt;
            &lt;select name="location" id="location" tabindex="2"&gt;
                &lt;option value=""&gt;&lt;/option&gt;
            &lt;/select&gt;
</code></pre>

<p>Thats my html. Right now I have my js, and it works, but I'm wondering if there is a petter way.</p>

<pre><code>        var State = $('#state').val();
        var Location = $('#location');



        setOptions(State);

        function setOptions(chosen){

        var Location=document.myform.location;
        Location.options.length=0;

        var Arizona = {
        0 : 'Select Location',
        3 : 'Phoenix (Chandler)',
        4 : 'Scottsdale',
        5 : 'Tuscon'
        };

        var Arkansas = {
        2 : 'Little Rock'
        };          

        var Colorado = {
        6 : 'Colorado Springs'
        };




        if(chosen=="Arizona"){              
        var myobject = Arizona;
        }

        if(chosen=="Arkansas"){
        var myobject = Arkansas;
        }

        if(chosen=="Colorado"){         
        var myobject = Colorado;
        }

        for(index in myobject) {
                Location.options[Location.options.length]=new Option(myobject[index], index);
        }
</code></pre>

<p>Is there a way I can tell it which object to use based on the other select box?</p>

<p>Thanks!     </p>
