title: Enabling and disabling form fields with JavaScript
body: <p>I am having trouble with getting the JavaScript to do what I need it to.  I have a form with a country drop down list that has United States or Other; then I have a State field with a list of all 50 states in the US; then I have a text field for people to put what country they live in if they don't live in the United States.  What I want to be able to do is if United Sates is selected in the country drop down list I want the "other" text field to be disabled and the state drop down list enabled; then vice versa, if they select other, then the state drop down list is disabled and the "other" text field is enabled.  <br />
  Here is the HTML code:  <br /></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  
  &lt;head&gt;
  &lt;script src="countryValidation.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div id="form2"&gt;
  &lt;form name="createForm" onsubmit="return createValidation();" method="get"&gt;
  &lt;p&gt;Country:    &lt;select id="country"&gt;
              &lt;option value="0"&gt;United States&lt;/option&gt;
              &lt;option value="1"&gt;Other&lt;/option&gt;
             &lt;/select&gt;&amp;nbsp;*&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
  &lt;p&gt;State:    &lt;select id="state"&gt;
            &lt;option value="0"&gt;- -Select state- -&lt;/option&gt;
            &lt;option value="Alabama"&gt;Alabama&lt;/option&gt;
            &lt;option value="Alaska"&gt;Alaska&lt;/option&gt;
            &lt;option value="Arizona"&gt;Arizona&lt;/option&gt;
            &lt;option value="Arkansas"&gt;Arkansas&lt;/option&gt;
            &lt;option value="California"&gt;California&lt;/option&gt;
            &lt;option value="Colorado"&gt;Colorado&lt;/option&gt;
            &lt;option value="Connecticut"&gt;Connecticut&lt;/option&gt;
            &lt;option value="Delaware"&gt;Delaware&lt;/option&gt;
            &lt;option value="Florida"&gt;Florida&lt;/option&gt;
            &lt;option value="Georgia"&gt;Georgia&lt;/option&gt;
            &lt;option value="Hawaii"&gt;Hawaii&lt;/option&gt;
            &lt;option value="Idaho"&gt;Idaho&lt;/option&gt;
            &lt;option value="Illinois"&gt;Illinois&lt;/option&gt;
            &lt;option value="Indiana"&gt;Indiana&lt;/option&gt;
            &lt;option value="Iowa"&gt;Iowa&lt;/option&gt;
            &lt;option value="Kansas"&gt;Kansas&lt;/option&gt;
            &lt;option value="Kentucky"&gt;Kentucky&lt;/option&gt;
            &lt;option value="Louisiana"&gt;Louisiana&lt;/option&gt;
            &lt;option value="Maine"&gt;Maine&lt;/option&gt;
            &lt;option value="Maryland"&gt;Maryland&lt;/option&gt;
            &lt;option value="Massachusetts"&gt;Massachusetts&lt;/option&gt;
            &lt;option value="Michigan"&gt;Michigan&lt;/option&gt;
            &lt;option value="Minnesota"&gt;Minnesota&lt;/option&gt;
            &lt;option value="Mississippi"&gt;Mississippi&lt;/option&gt;
            &lt;option value="Missouri"&gt;Missouri&lt;/option&gt;
            &lt;option value="Montana"&gt;Montana&lt;/option&gt;
            &lt;option value="Nebraska"&gt;Nebraska&lt;/option&gt;
            &lt;option value="Nevada"&gt;Nevada&lt;/option&gt;
            &lt;option value="New Hampshire"&gt;New Hampshire&lt;/option&gt;
            &lt;option value="New Jersey"&gt;New Jersey&lt;/option&gt;
            &lt;option value="New Mexico"&gt;New Mexico&lt;/option&gt;
            &lt;option value="New York"&gt;New York&lt;/option&gt;
            &lt;option value="North Carolina"&gt;North Carolina&lt;/option&gt;
            &lt;option value="North Dakota"&gt;North Dakota&lt;/option&gt;
            &lt;option value="Ohio"&gt;Ohio&lt;/option&gt;
            &lt;option value="Oklahoma"&gt;Oklahoma&lt;/option&gt;
            &lt;option value="Oregon"&gt;Oregon&lt;/option&gt;
            &lt;option value="Pennsylvania"&gt;Pennsylvania&lt;/option&gt;
            &lt;option value="Rhode Island"&gt;Rhode Island&lt;/option&gt;
            &lt;option value="South Carolina"&gt;South Carolina&lt;/option&gt;
            &lt;option value="South Dakota"&gt;South Dakota&lt;/option&gt;
            &lt;option value="Tennessee"&gt;Tennessee&lt;/option&gt;
            &lt;option value="Texas"&gt;Texas&lt;/option&gt;
            &lt;option value="Utah"&gt;Utah&lt;/option&gt;
            &lt;option value="Vermont"&gt;Vermont&lt;/option&gt;
            &lt;option value="Virginia"&gt;virginia&lt;/option&gt;
            &lt;option value="Washington"&gt;Washington&lt;/option&gt;
            &lt;option value="West Virginia"&gt;West Virginia&lt;/option&gt;
            &lt;option value="Wisconsin"&gt;Wisconsin&lt;/option&gt;
            &lt;option value="Wyoming"&gt;Wyoming&lt;/option&gt;
           &lt;/select&gt;&amp;nbsp;*&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
   &lt;p&gt;Please type in what country you live in:
  &lt;input type="text" id="countryOther" /&gt;&amp;nbsp;*&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
  </code></pre>
  
  <p><br />
  And here is what I am trying to do with JavaScript:</p>
  
  <pre><code>function countryValidation ()
   {
    var country = document.forms["createForm"]["country"].value;
    var countryOther = document.forms["createForm"]["countryOther"];
    var state = document.forms["createForm"]["state"];
  
    if (country == 0)
     {
     countryOther.createAttribute("disabled","disabled");
     }
    else if (country == 1)
     {
     state.createAttribute("disabled","disabled");
     countryOther.removeAttribute("disabled");
      }
   }
  </code></pre>
  
  <p>I do have another JavaScript function that Validates the whole form, because it is a form that I will be using to allow people to create an account.  I haven't gotten to the point of having an SQL server, nor have I learned SQL, PHP or ASP.net...  I am doing this for a project and could really use some help with this problem.</p>
  
  <p>Thanks!</p>