title: Form Validation with password match
body: <p>I have two forms inside my body:</p>
  
  <pre><code>&lt;body&gt;
      &lt;form method=post name="signin"&gt;
          &lt;table&gt;
              &lt;theader&gt;Sign In&lt;/theader&gt;
              &lt;tr&gt;
                  &lt;td&gt;Email:&lt;/td&gt;
                  &lt;td&gt;
                      &lt;input type=text length=25 maxlength=25 name=em id=em /&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;Password:&lt;/td&gt;
                  &lt;td&gt;
                      &lt;input type=password length=15 maxlength=15 name=up id=up /&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td colspan=2&gt;
                      &lt;input type=button value="submit" /&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
      &lt;/form&gt;
      &lt;br&gt;
      &lt;br&gt;
      &lt;br&gt;
      &lt;br&gt;
      &lt;form method=post name="register"&gt;
          &lt;table&gt;
              &lt;theader&gt;Don't have an account? Register, it's Free!&lt;/theader&gt;
              &lt;tr&gt;
                  &lt;td&gt;Email:&lt;/td&gt;
                  &lt;td&gt;
                      &lt;input type=text length=25 name=email id=email /&gt;&lt;span id="nameerror"&gt;&lt;/span&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;Password:&lt;/td&gt;
                  &lt;td&gt;
                      &lt;input type=password length=15 name=pass id=pass /&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;Confirm Password:&lt;/td&gt;
                  &lt;td&gt;
                      &lt;input type=password length=15 name=cpass id=cpass /&gt;&lt;span id="pwerror"&gt;&lt;/span&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;Account Type:&lt;/td&gt;
                  &lt;td&gt;
                      &lt;select id="seltype"&gt;
                          &lt;option name=standard SELECTED&gt;Standard&lt;/option&gt;
                          &lt;option name=admin&gt;Administrator&lt;/option&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td colspan=2&gt;
                      &lt;input type=button value="submit" onClick="JavaScript:validate();" /&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>I would like to do the following:
  For each form, validate to ensure it's filled in and also for the second form I want to validate that the two password matched. I have the following:</p>
  
  <pre><code>$( document ).ready(function() {
  
      var t = document.getElementById("email").value;
      var y = document.getElementById("seltype").value;
      var k = document.getElementById("pass").value;
      var j = document.getElementById("cpass").value;
  
      $('#cpass').blur(function(){    
          if (k != j) {
              document.getElementById("pwerror").innerHTML = "Password does not match";
          }
          else {
              document.getElementById("pwerror").innerHTML = "Password matches";
          }
      }); 
  });
  
  function validate() {   
      if (t != null &amp;&amp; y != null &amp;&amp; k != null &amp;&amp; j != null) {
      }
      if (t == "" || y == "" || k == "" || j == "") {
          alert("fill in");
      }
  }
  </code></pre>