title: Why does my HTML form still submit when I return false from onsubmit?
body: <p>I wrote a simple script for validating login form as follows:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      function validateLoginForm(){
      var idV = document.forms["LoginForm"]["id"].value;
      var pwdV = document.forms["LoginForm"]["pwd"].value;
  
      if (idV == null || idV == "" || idV.length &lt; 5) {
            alert("user ID must be filled and of more than 4 characters!!");
            id.focus();
            return false;
      }
  
      if (pwdV == null || pwdV == "" || pwdV.length &lt; 5) {
          alert("Password must be filled and of more than 4 characters!!");
          pwd.focus();
          return false;
      }
  
      return true;
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>and call it as :</p>
  
  <pre><code>&lt;form name="LoginForm" method="POST" onsubmit="return validateLoginForm()" action="Login" &gt;
  .
  .
  .
  .
  &lt;/form&gt;
  </code></pre>
  
  <p>The problem is that javaScript gives out the alert as i set correctly but in the end the <code>Login</code> servlet also called automatically, which is a wrong thing..Why this happens? Any solution?</p>