title: javascript validation errors to be displayed after each textbox
body: <p>I am quite stuck with the validation part with different requirement in validation. Below is the list which i am working for my application module:
  a. Form will consist of two input fields (name and email) and a submit button.
  b. On submit, the validation should check if the fields are empty.
  c. If any field is empty, the text colour as well as border of the field should turn red. (No need to show an error message)
  d. When I start typing in the field, The text and border colour should return to default colour.</p>
  
  <p>Below is the code which i had tried:</p>
  
  <h2>HTML</h2>
  
  <pre><code>&lt;center&gt;
      &lt;table border="1"&gt;
          &lt;tr&gt;
              &lt;td&gt;
                  &lt;form name="registerationform" method="POST" action="welcome.html" onsubmit="return(regvalidate())"&gt;
                      &lt;table&gt;
                          &lt;tr&gt;
                              &lt;td&gt;First Name:&lt;/td&gt;
                              &lt;td&gt;
                                  &lt;input type="text" name="fnametxt" /&gt;
                                  &lt;br/&gt;
                              &lt;/td&gt;
                          &lt;/tr&gt;
                          &lt;tr&gt;
                              &lt;td&gt;Second Name:&lt;/td&gt;
                              &lt;td&gt;
                                  &lt;input type="text" name="snametxt" /&gt;
                                  &lt;br/&gt;
                              &lt;/td&gt;
                          &lt;/tr&gt;
                          &lt;tr&gt;
                              &lt;td&gt;User Name:&lt;/td&gt;
                              &lt;td&gt;
                                  &lt;input type="text" name="unametxt" /&gt;
                                  &lt;br/&gt;
                              &lt;/td&gt;
                          &lt;/tr&gt;
                          &lt;tr&gt;
                              &lt;td&gt;Email Address:&lt;/td&gt;
                              &lt;td&gt;
                                  &lt;input type="text" name="emailtxt" /&gt;
                                  &lt;br/&gt;
                              &lt;/td&gt;
                          &lt;/tr&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Password :&lt;/td&gt;
              &lt;td&gt;
                  &lt;input type="password" name="pwdtxt" /&gt;
                  &lt;br/&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Confirm :&lt;/td&gt;
              &lt;td&gt;
                  &lt;input type="password" name="cpwdtxt" /&gt;
                  &lt;br/&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;/table&gt; &lt;font color='red'&gt; &lt;DIV id="une"&gt; &lt;/DIV&gt; &lt;/font&gt;
  
          &lt;input type="submit" value="Register Now" /&gt;
          &lt;/form&gt;
          &lt;/td&gt;
          &lt;/th&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
      &lt;/tr&gt;
      &lt;/table&gt;
      &lt;/tr&gt;
      &lt;/td&gt;
      &lt;/tr&gt;
      &lt;/table&gt;
  &lt;/center&gt;
  </code></pre>
  
  <h2>JavaScript</h2>
  
  <pre><code>function regvalidate() a {
      if ((document.registerationform.fnametxt.value == "") &amp;&amp; (document.registerationform.snametxt.value == "")) {
          document.getElementById('une').innerHTML = "First name or Second name should not be empty";
          registerationform.fnametxt.focus();
          return (false);
      }
  
      if (document.registerationform.unametxt.value == "") {
          document.getElementById('une').innerHTML = "User name field should not be empty";
          registerationform.unametxt.focus();
          return (false);
      }
  
      if (document.registerationform.emailtxt.value == "") {
          document.getElementById('une').innerHTML = "Email id requered";
          registerationform.emailtxt.focus();
          return (false);
      }
  
      if (document.registerationform.pwdtxt.value == "") {
          document.getElementById('une').innerHTML = "Please type a password";
          registerationform.pwdtxt.focus();
          return (false);
      }
  
      if ((document.registerationform.pwdtxt.value) != (document.registerationform.cpwdtxt.value)) {
          document.getElementById('une').innerHTML = "Password Must be equal";
          registerationform.pwdtxt.value = "";
          registerationform.cpwdtxt.value = "";
          registerationform.pwdtxt.focus();
          return (false);
      } else {
          return (true);
      }
  }
  </code></pre>
  
  <p>The above form works for all the fields but i need only two as specified above as well as the textbox border coloring for errors.
  Really need help. If someone could plese help me out</p>