title: Javascript form validation not working?
body: <p>Can't for the life of me figure this out. The form validation STOPS working once I get to the "countrySelect" id. Even if I fill this in, and try to get it to show the alert for the zip or phone field it doesn't work, it continues submitting the form. However, the alerts work when an input before the countrySelect id is blank. I don't quite understand...</p>
  
  <p>Here is the form:</p>
  
  <pre><code>&lt;form action="&lt;?php echo $_SERVER['PHP_SELF'] ?&gt;" method="post" name="addAffiliate" id="addAffiliate" onsubmit="return ValidateApplication()"&gt;
              &lt;div id="affiliatesignup"&gt;
                &lt;ul&gt;
                  &lt;li&gt;
                    &lt;label&gt;First Name&lt;/label&gt;
                    &lt;input type="text" name="firstname" id="firstname" value="&lt;?php echo $firstname ;?&gt;" /&gt;
                  &lt;/li&gt;
                  &lt;li&gt;
                    &lt;label&gt;Last Name&lt;/label&gt;
                    &lt;input type="text" name="lastname" id="lastname"  value="&lt;?php echo $lastname ;?&gt;" /&gt;
                  &lt;/li&gt;
                   &lt;li&gt;
                    &lt;label&gt;Username&lt;/label&gt;
                    &lt;input type="text" name="username" id="username"  value="&lt;?php echo $username ;?&gt;" /&gt; 
                    &lt;label&gt; &lt;/label&gt;
                    &lt;div style="margin-left:130px;font-size:11px;"&gt;(Note: Your username will appear in all your affiliate links, so choose wisely!)&lt;/div&gt;
                  &lt;/li&gt;
                  &lt;li&gt;
                    &lt;label&gt;Email&lt;/label&gt;
                    &lt;input type="text" name="email" id="email"  value="&lt;?php echo $email ;?&gt;" /&gt;
                  &lt;/li&gt;
                  &lt;li&gt;
                    &lt;label&gt;Password&lt;/label&gt;
                    &lt;input  type="password" size="30" name="password" id="password" value="&lt;?php echo $password ;?&gt;"/&gt;
                  &lt;/li&gt;
                  &lt;li&gt;
                    &lt;label&gt;Confirm Password&lt;/label&gt;
                    &lt;input type="password" size="30" name="passwordc" id="passwordc" value="&lt;?php echo $passwordc ;?&gt;"/&gt;
                  &lt;/li&gt;
                  &lt;div class="form-break"&gt;&lt;/div&gt;
                  &lt;li&gt;
                    &lt;label&gt;Mailing Address&lt;/label&gt;
                    &lt;input type="text" name="address" id="address"  value="&lt;?php echo $address ;?&gt;" /&gt;
                  &lt;/li&gt;
                  &lt;li&gt;
                    &lt;label&gt;City&lt;/label&gt;
                    &lt;input type="text" name="city" id="city"  value="&lt;?php echo $city ;?&gt;" /&gt;
                  &lt;/li&gt;
                  &lt;li&gt;
                    &lt;label&gt;Country&lt;/label&gt;
                    &lt;select id='countrySelect' name='countrySelect' onchange='populateState()'&gt;
                    &lt;/select&gt;
                  &lt;/li&gt;
                   &lt;li&gt;
                    &lt;label&gt;State/Province&lt;/label&gt;
                    &lt;select id='stateSelect' name='stateSelect'&gt;
                    &lt;/select&gt;
                    &lt;script type="text/javascript"&gt;initCountry('US'); &lt;/script&gt;
                  &lt;/li&gt;
                  &lt;li&gt;
                    &lt;label&gt;Zip/Postal Code&lt;/label&gt;
                    &lt;input type="text" name="zip" id="zip"  value="&lt;?php echo $zip ;?&gt;" /&gt;
                  &lt;/li&gt;
                  &lt;li&gt;
                    &lt;label&gt;Phone Number&lt;/label&gt;
                    &lt;input type="text" name="phone" id="phone"  value="&lt;?php echo $phone ;?&gt;" /&gt;
                  &lt;/li&gt;
                  &lt;div class="form-break"&gt;&lt;/div&gt;
                  &lt;li&gt;
                    &lt;label&gt;Payment Type&lt;/label&gt;
                    &lt;select name="payment_type" id="payment_type" onChange="paymentfunction(this.value);"&gt;
                      &lt;option value=""&gt;Select Payment Type&lt;/option&gt;
                      &lt;option value="check"&gt;Check&lt;/option&gt;
                      &lt;option value="paypal"&gt;Paypal&lt;/option&gt;
                    &lt;/select&gt;
                  &lt;/li&gt;
                  &lt;li id="check-payable-to" style="display:none;"&gt;
                    &lt;label&gt;Check Payable To&lt;/label&gt;
                    &lt;input type="text" name="check_payable_to" id="check_payable_to"  value="&lt;?php echo $check_payable_to ;?&gt;" /&gt;
                  &lt;/li&gt;
                  &lt;li id="paypal-email" style="display:none;"&gt;
                    &lt;label&gt;Paypal Email&lt;/label&gt;
                    &lt;input type="text" name="paypal" id="paypal"  value="&lt;?php echo $paypal ;?&gt;" /&gt;
                  &lt;/li&gt;
                  &lt;div class="form-break"&gt;&lt;/div&gt;
                  &lt;li&gt;
                    &lt;label&gt;Website&lt;/label&gt;
                    &lt;input type="text" name="website" id="website"  value="&lt;?php echo $website ;?&gt;" /&gt;
                  &lt;/li&gt;
                  &lt;li&gt;
                    &lt;label&gt;How do you plan to promote us?&lt;/label&gt;
                    &lt;textarea rows="4" name="promotion" id="promotion" type="text"&gt;&lt;?php echo $promotion ;?&gt;&lt;/textarea&gt;
                  &lt;/li&gt;
                &lt;/ul&gt;
                &lt;input type="hidden" value="&lt;?php echo $affiliate ; ?&gt;" name="affiliate" id="affiliate" /&gt;
                &lt;input type="submit" value="Register" class="button-glossy green" id="bCreateAccount" tabindex="4" /&gt;
              &lt;/div&gt;
            &lt;/form&gt;
  </code></pre>
  
  <p>Here is the javascript function contained in the head of the page:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
      function ValidateApplication() {
  
              firstname = document.getElementById("firstname");
              lastname = document.getElementById("lastname");
              username = document.getElementById("username");
              email = document.getElementById("email");
              password = document.getElementById("password");
              passwordc = document.getElementById("passwordc");
              address = document.getElementById("address");
              city = document.getElementById("city");
              country = document.getElementById("countrySelect");
              state = document.getElementById("stateSelect");
              zip = document.getElementById("zip");
              phone = document.getElementById("phone");
              payment_type = document.getElementById("payment_type");
              check_payable_to = document.getElementById("check_payable_to");
              paypal = document.getElementById("paypal");
              website = document.getElementById("website");
              promotion = document.getElementById("promotion");
  
              if (firstname.value.length == 0) {
                  alert("You must enter your first name");
                  firstname.style.border = '1px solid #fa0404';
                  firstname.focus();
                  return false;   
              }
              if (lastname.value.length == 0) {
                  alert("You must enter your last name");
                  lastname.style.border = '1px solid #fa0404';
                  lastname.focus();
                  return false;   
              }
              if (username.value.length == 0) {
                  alert("You must enter a user name");
                  username.style.border = '1px solid #fa0404';
                  username.focus();
                  return false;   
              }
              if (email.value.length == 0) {
                  alert("You must enter your email address");
                  email.style.border = '1px solid #fa0404';
                  email.focus();
                  return false;   
              }
              if (password.value.length == 0) {
                  alert("You must enter a password");
                  password.style.border = '1px solid #fa0404';
                  password.focus();
                  return false;   
              }
              if (passwordc.value.length == 0) {
                  alert("You must confirm your password");
                  passwordc.style.border = '1px solid #fa0404';
                  passwordc.focus();
                  return false;   
              }
              if (password.value != passwordc.value) {
                  alert("You passwords must match");
                  password.style.border = '1px solid #fa0404';
                  passwordc.style.border = '1px solid #fa0404';
                  password.focus();
                  return false;   
              }
              if (address.value.length == 0) {
                  alert("You must enter your mailing address");
                  address.style.border = '1px solid #fa0404';
                  address.focus();
                  return false;   
              }
              if (city.value.length == 0) {
                  alert("You must enter your city");
                  city.style.border = '1px solid #fa0404';
                  city.focus();
                  return false;   
              }
              if (countrySelect.value.length == 0) {
                  alert("You must enter your country");
                  countrySelect.style.border = '1px solid #fa0404';
                  countrySelect.focus();
                  return false;   
              }
              if (stateSelect.value.length == 0) {
                  alert("You must enter your state/province");
                  stateSelect.style.border = '1px solid #fa0404';
                  stateSelect.focus();
                  return false;   
              }
              if (zip.value.length == 0) {
                  alert("You must enter your zip/postal code");
                  zip.style.border = '1px solid #fa0404';
                  zip.focus();
                  return false;   
              }
              if (phone.value.length == 0) {
                  alert("You must enter your phone number");
                  phone.style.border = '1px solid #fa0404';
                  phone.focus();
                  return false;   
              }
              if (payment_type.value.length == 0) {
                  alert("You must select your payment type");
                  payment_type.style.border = '1px solid #fa0404';
                  payment_type.focus();
                  return false;   
              }
              if (payment_type.value == 'check') {
                  if (check_payable_to.value.length == 0) {
                      alert("You must enter the name your check is payable to");
                      check_payable_to.style.border = '1px solid #fa0404';
                      check_payable_to.focus();
                      return false;   
                  }   
              }
              if (payment_type.value == 'paypal') {
                  if (paypal.value.length == 0) {
                      alert("You must enter paypal email address");
                      paypal.style.border = '1px solid #fa0404';
                      paypal.focus();
                      return false;   
                  }   
              }
              if (website.value.length == 0) {
                  alert("You must enter your website address");
                  website.style.border = '1px solid #fa0404';
                  website.focus();
                  return false;   
              }
              if (promotion.value.length == 0) {
                  alert("You must enter your promotional plans");
                  promotion.style.border = '1px solid #fa0404';
                  promotion.focus();
                  return false;   
              }
  
      }
      &lt;/script&gt;
  </code></pre>