title: How can I prevent a form action if my JavaScript functions have returned false?
body: <p>I'm very inexperienced with programming so sorry if this is stupid question.</p>
  
  <p>I'm creating a form which the user will be able to submit using a button. I have used script functions to decide whether they will return true or false, with the only condition being that the input boxes must be filled. Here is a simplified version of my JavaScript and HTML code, I've only included one of the input boxes. (My real code has six)</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function validateEmail() {
      var x = document.forms["myForm"]["email"].value;
      if (x == null || x == "") {
          alert("Email must be filled out");
          return false;
   }
   else {
    return true;
   }
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;form name="myForm" 
  onsubmit="validateEmail()" method="post" action="Different_Page.html"&gt;
    
  &lt;label for="email"&gt;Email Address:&lt;/label&gt;
  &lt;input type="email" name="email"&gt;
    
  &lt;input type="submit" value="Submit"&gt;
  &lt;/form&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>The issue is that if the user does not type in their email and the function returns false, it still goes to the page I only want it to go to when it returns true. So in other words, I want it to do nothing and stay on this page, but ONLY when the script returns false. How do I accomplish this?</p>