title: prevent login Form from submission (AJAX) when credentials dont match (return false not working)
body: <p>This is my form:</p>
  
  <pre><code> &lt;form name="loginform" method="POST" action="login" onsubmit="return validateLogin()"&gt;            
  &lt;div&gt;  User Name  :&lt;input class="input" name="username" type="text" /&gt; &lt;/div&gt; 
  &lt;div&gt; Password  :&lt;input class="input" name="password" type="password" /&gt; &lt;/div&gt;        
  &lt;div&gt; id="yaha" style="color:red;font:bold 16px garamond"&lt;/div&gt;                         
  &lt;input style="font-weight:bold;" type="submit" value="Login" /&gt;
  </code></pre>
  
  <p>javascript code is as shown:</p>
  
  <pre><code>function validateLogin()
  {
  var x1=document.forms["loginform"];
  if(//validations)
        {
         return false;
        }
   else
  {    goajax(x1.username.value,x1.password.value);}        
   }//validate login ends...
  
  var requ = null;
  
  function goajax( u,  p)
  {
  requ=new XMLHttpRequest();
  //code for posting ajax data
  requ.onreadystatechange=display;
  
  } 
  function display()
  {
  if(requ.readyState == 4)
  {
      if(requ.status == 200)
      {
      var message = requ.responseText;
      alert("message==="+message);
      var x;
      if(message.trim() == "ok")
          {
          var x1=document.forms["loginform"];
          return true;
          }
          else if(message.trim() == "no")
          {
          document.getElementById('yaha').innerHTML="Invalid Username or Password!!!";
          x1.password.value="";
          return false;
          }
          else if(message.trim() == "nv")
          {
          document.getElementById('yaha').innerHTML="Account not Activated";
          return false;
          }
      }     
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>My question is</strong>: I am getting the responses from the server as desired but in case of undesired responses, the form is getting submitted even after "return false;" (see function display())</p>
  
  <p><strong>Please scroll down to function display() i don't want the form to be submitted when message is "no" or "nv". basically "return false" is not working</strong></p>