title: returning false not stopping the submission of form
body: <p>My purpose: If the user field and password field are blank, I want to stop form submitting.
  This is my Code that I am trying:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;script&gt;
          function doit() {
  
              var usr = document.getElementById('ur').value;
              var psw = document.getElementById('pw').value;
  
              if ((usr.trim() == '') &amp;&amp; (psw.trim() == '')) {
                  alert("cannot Submit form");
                  return false;
              }
  
          }
      &lt;/script&gt;
  
  &lt;/head&gt;
  
  
  &lt;body&gt;
  
      &lt;form action="post.php" method="post" onsubmit="doit()"&gt;
          User:
          &lt;input type="text" id="ur" name="user"&gt;
          &lt;br&gt;
          &lt;br&gt; Pass:
          &lt;input type="password" id="pw" name="pass"&gt;
          &lt;br&gt;
          &lt;br&gt;
          &lt;button&gt;Submit&lt;/button&gt;
      &lt;/form&gt;
  
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I am learning JavaScript. Will be helpful if you correct the code with a little explanation why it is not working. </p>