title: validate confirmed password?
body: <p>I am trying to validate the password field using javascript. Making sure when the user retypes the password in the confirm password field, it should be the same.</p>
  
  <p>here is what i tried to do. This is the form. The onsubmit = "validate_reg()" is another validation using javascript to make sure all the fields must be filled. </p>
  
  <pre><code>&lt;form name="register" action="signup.php" onsubmit="return validate_reg()"enctype="multipart/form-data" method="post" &gt;
  &lt;table width="600" border="0"&gt;
  &lt;tr&gt;&lt;td width="210" height="45"&gt;Username*:&lt;/td&gt;&lt;td&gt;
  &lt;input type="text" size="40" name="userUsername" id="user_username" /&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td width="210" height="45"&gt;Password*:&lt;/td&gt;&lt;td&gt;
  &lt;input type="password" size="40" name="userPassword" id="user_password"/&gt;&lt;/td&gt;&lt;/tr&gt; 
      &lt;tr&gt;&lt;td width="210" height="45"&gt;Re-type Password:&lt;/td&gt;&lt;td&gt;
  &lt;input type="password" size="40" name="userPasswordConfirm" 
       id="user_password_confirm"/&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;/table&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>This is the javascript codes:</p>
  
  <pre><code>&lt;!--================Javascript for the validation of the Password Confirmation==========================--&gt;
  &lt;script type="text/javascript" language="javascript"&gt;
  
  function validatepw() {
    if ( document.register.user_password.value != document.register.user_password_confirm.value)
      {
      alert('Passwords did not match!');
          return false;
          }else{
          document.register.submit();
          return true;
      }
      }
  &lt;/script&gt;
  
  &lt;!--================Javascript for the validation of the required fields ================================--&gt;
  &lt;script type="text/javascript"&gt;
  
      function validate_reg()
      {
      var isValid = true;
  
      // using OLD method of using name to find the control
  
      if ( document.register.user_username.value == "")
      {
      document.register.user_username.style.backgroundColor="red";
      isValid=false;
      }
      else{
      document.register.user_username.style.backgroundColor="white";
      }
      if ( document.register.user_password.value == "")
      {
      document.register.user_password.style.backgroundColor="red";
      isValid=false;
      }
      else{
      document.register.user_password.style.backgroundColor="white";
      }
      if ( document.register.user_password_confirm.value == "")
      {
      document.register.user_password_confirm.style.backgroundColor="red";
      isValid=false;
      }
      else{
      document.register.user_password_confirm.style.backgroundColor="white";
      }
  }
  &lt;/script&gt;
  </code></pre>