On state select change country
<p>I have two lists (one of states) and one of (countries). I want to have it so when a user selects Alberta it sets the country to Canada, and so on and so forth.</p>

<p>I have the following javascript</p>

<pre><code>var states = new Array(12)

states[0] = "AB";
states[1] = "BC";
states[2] = "MB";
states[3] = "NB";
states[4] = "NL";
states[5] = "NT";
states[6] = "NV";
states[7] = "NS";
states[8] = "ON";
states[9] = "PE";
states[10] = "QC";
states[11] = "SK";
states[12] = "YK";

function oc(a)
{
  var o = {};
  for(var i=0;i&lt;a.length;i++)
  {
    o[a[i]]='';
  }
  return o;
}

if(oc(document.forms[0].state_o.value) in states) {
    document.forms[0].country_o.options("Canada").selected = true;
}
</code></pre>

<p>State List</p>

<pre><code>&lt;select name="state_o" id="state_o"&gt;
                                                        &lt;option value=''&gt;&lt;/option&gt;
&lt;option value="AB" style='color: red'&gt;Alberta&lt;/option&gt;
&lt;option value="BC" style='color: red'&gt;British Columbia&lt;/option&gt;
&lt;option value="MB" style='color: red'&gt;Manitoba&lt;/option&gt;
&lt;option value="NB" style='color: red'&gt;New Brunswick&lt;/option&gt;
&lt;option value="NL" style='color: red'&gt;Newfoundland&lt;/option&gt;
&lt;option value='NT' style='color: red'&gt;Northwest Territories&lt;/option&gt;
&lt;option value='NV' style='color: red'&gt;Nunavut&lt;/option&gt;
&lt;option value="NS" style='color: red'&gt;Nova Scotia&lt;/option&gt;
&lt;option value="ON" style='color: red'&gt;Ontario&lt;/option&gt;
&lt;option value="PE" style='color: red'&gt;Prince Edward Island&lt;/option&gt;
&lt;option value="QC" style='color: red'&gt;Quebec&lt;/option&gt;
&lt;option value="SK" style='color: red'&gt;Saskatchewan&lt;/option&gt;
&lt;option value='YK'  style='color: red'&gt;Yukon Territory&lt;/option&gt;
</code></pre>

<p>Country List</p>

<pre><code>    &lt;select name="country_o"&gt;
                                                    &lt;option value=''&gt;&lt;/option&gt;
                                                    &lt;option value="Canada"&gt;Canada&lt;/option&gt;
                                                    &lt;option value="United States"&gt;United States&lt;/option&gt;
                                                    &lt;option value="Europe"&gt;Europe&lt;/option&gt;
                                                &lt;/select&gt;
</code></pre>

<p>Now the problem is it doesn't seem to be working. I'm setting up an array, and then converting it to an object using oc function then checking to see if it is in the object list and if it is set the proper country selected to true.</p>

<p>Any help?</p>
