title: form submit always return true while it should return false
body: <p>I'm validating a form before submitting using this code</p>
  
  <pre><code>&lt;form method="post" onsubmit="return reg()"&gt;
  &lt;table&gt;
  &lt;tr&gt;
  &lt;td&gt;Name&lt;/td&gt;
  &lt;td&gt;&lt;input type="text" name="username" id="username" autocomplete="off" &gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Password&lt;/td&gt;
  &lt;td&gt;&lt;input type="password" name="password" id="password" autocomplete="off" &gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Email&lt;/td&gt;
  &lt;td&gt;&lt;input type="email" name="email" id="email" autocomplete="off"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Phone&lt;/td&gt;
  &lt;td&gt;&lt;input type="text" name="phone" id="phone" autocomplete="off" placeholder="001**********"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td colspan="2"&gt;&lt;input type="submit" name="register" id="register" value="register"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>and this js code</p>
  
  <pre><code>function reg(){
      var user = $("#username").val(),
          pass = $("#password").val(),
          city = $("#city").val(),
          email = $("#email").val(),
          phone = $("#phone").val();
  
      if(user.length&lt;4){
          alert('short name');
          return false;
      }
      else if(pass.length&lt;6) {
          alert('password error');
          return false;
      }
      else if(city.length&lt;3) {
          alert('city error');
          return false;
      }
      else if(phone.length&lt;6) {
          alert('phone error');
          return false;
      }
      else{
          $.post('ajax/checkex.php?user='+user+"&amp;email="+email).done(function (data) {
              if(data.indexOf('user') !== -1){
                  alert('user name is not available');
                  return false;
              }
              else if(data.indexOf('email') !== -1){
                  alert('email address is already registered');
                  return false;
              }
              else if(data.indexOf('available') !== -1){
                  return true;
              }
          });
        //return false;
      }
  }
  </code></pre>
  
  <p>But the form always submits and the ajax code does not work at all. It does not  even alert anything inside like <code>alert(data)</code>.</p>
  
  <p>The js code returns true even though the name and the email are already registered before.</p>
  
  <p>When I uncomment the last <code>return false</code> line it returns false and the ajax works fine but sure the form does not submit at all. So where's the error in this code?</p>