title: html form validation not working
body: <p>I was working on a html form where I have to enter user information and on submit. It will navigate to the php connection page. The problem is that I have been trying to validate the data before submitting through JavaScript and it's not happening. </p>
  
  <p>Below I am posting the HTML form code.</p>
  
  <pre><code>    &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;script language = "JavaScript"&gt;
          function validate()
          {
              var username = document.getElementById("userName").value;
              var password = document.getElementById("Password").value;
              var repassword = document.getElementById("RePassword").value;
  
              if (username.length &lt; 0) {
                  alert("Please enter the username.");
                  return false;
              }
              if (password == null || password == "") {
                  alert("Please enter the password.");
                  return false;
              }
               if (repassword == null || repassword == "" || repassword != password) {
                  alert("Please enter the password.");
                  return false;
              }
  
  
          } 
  &lt;/script&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
  &lt;form name="frmMr" action="send_post.php" method="post"  onsubmit="return(validate());"&gt;
      User Name:&lt;br&gt; &lt;input type="text" name="userName"&gt;&lt;br&gt;
      Enter Password:&lt;br&gt; &lt;input type="text" name="Password"&gt;&lt;br&gt;
      Reenter Password:&lt;br&gt; &lt;input type="text" name="RePassword"&gt;&lt;br&gt;
      &lt;input type="submit" &gt;
  &lt;/form&gt;
  &lt;p id="error_para" &gt;&lt;/p&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>