title: How do I disable form dropdown option using javascript
body: <p>I'm trying to disable the "name" text field in the form when "Choose" is selected in the drop down <em>after</em> the page loads (it's disabled when the page loads) ie after I've chosen one of the other two options that disable or enable that field, when I return to "Choose" i'd like the same field to disable. I can't see why the javascript I've written would prevent this from happening. Thanks!</p>
  
  <p>
      
          
              </p>
  
  <pre><code>        &lt;script type="text/javascript"&gt;
  
      function clickclear(thisfield, defaulttext) {
          if (thisfield.value === defaulttext) {
              thisfield.value = "";
          }
      }
  
      function clickrecall(thisfield, defaulttext) {
          if (thisfield.value === "") {
              thisfield.value = defaulttext;
          }
      }
  
      function checkPickup() {
  
          if (form.os0.value != "Pickup from Toowong, Brisbane" ) {
              form.name.disabled = false; form.name.style.color = '#333';
  
          } else {
  
              form.name.disabled = true; form.name.style.color = '#CCC';
              /* Reset form values */
              form.name.value = "His/her name";
          }
      }
  &lt;/script&gt;
  
  &lt;script type="text/javascript"&gt;
      function validate(form) {
  
          var errmsg = "Oops, you're required to complete the following fields! \n";
  
          // Various other form validations here
  
          // Validate "Pickup"
          if (form.os0.value === "") {
              errmsg = errmsg + " - Choose pickup or delivery\n";
          }
  
          // Validate "phone"
          if (form.phone.value === "" || form.phone.value === "Mobile's best!") {
              errmsg = errmsg + " - Your phone number\n";
          }
  
  
          if (form.os0.value != "Pickup from Toowong, Brisbane") {
  
              // Validate "name"
              if (form.name.value === "" || form.name.value === "His/her name") {
                  errmsg = errmsg + " - His/her name\n";
              }
          }
  
          // Alert if fields are empty and cancel form submit
          if (errmsg === "Oops, you're required to complete the following fields! \n") {
              form.submit();
          } else {
              alert(errmsg);
              return false;
          }
      }
  &lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;form name="form" action="https://www.paypal.com/cgi-bin/webscr" method="post" onSubmit="return validate(form)"&gt;
  
              &lt;p class="row"&gt;
                  &lt;input type="hidden" name="on0" value="Pickup and delivery" /&gt;Pickup and delivery&lt;br /&gt;
                  &lt;select name="os0" onchange="checkPickup()"&gt;
                      &lt;option value="" selected &gt;Choose&lt;/option&gt;
                      &lt;option value="Pickup from Toowong, Brisbane"&gt;Pickup from Toowong, Brisbane $1.00 AUD&lt;/option&gt;
                      &lt;option value="Brisbane +$23.60"&gt;Brisbane +$23.60 =$1.00 AUD&lt;/option&gt;
                  &lt;/select&gt;
              &lt;/p&gt;
              &lt;p class="row"&gt;Your daytime phone number&lt;br /&gt;
                  &lt;input type="text" name="phone" value="Mobile's best!" onclick="clickclear(this, 'Mobile\'s best!')" onblur="clickrecall(this,'Mobile\'s best!')" /&gt;
              &lt;/p&gt;
              &lt;p class="row"&gt;Recipient's name&lt;br /&gt;
                  &lt;input style="color: #ccc" class="name" type="text" name="name" value="His/her name" onclick="clickclear(this, 'His/her name')" onblur="clickrecall(this,'His/her name')" disabled /&gt;
              &lt;/p&gt;
              &lt;input name="custom" type="hidden"  /&gt;
              &lt;input type="hidden" name="currency_code" value="AUD" /&gt;
              &lt;input class="button" type="image" src="https://www.paypalobjects.com/en_AU/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal — The safer, easier way to pay online." /&gt;
              &lt;img alt="" border="0" src="https://www.paypalobjects.com/en_AU/i/scr/pixel.gif" width="1" height="1"&gt; --&gt;
          &lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>