title: Is there a way to pause or wait for a function to finish before onsubmit action in form
body: <p>I have a simple example, I found out that onsubmit requires a return value right away. I have a function that pauses 5 seconds and wait till it completes then returns the boolean value back to simulate other javascript processing action. However, the page form submission still triggers even before my function manages to return anything values. So what should I do, would using callback in JS help in my case? </p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  
  &lt;form action="test.html" onsubmit="return testing();"&gt;
  &lt;button type="submit"&gt; hello world &lt;/button&gt;
  &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;script&gt;
  function testing()
  {
      var newState = -1;
      setTimeout(function() {
      if (newState == -1) {
        alert('VIDEO HAS STOPPED');
        output = "newText";
        console.log("AFTER 5 Sec: " + output);
        return false;
      }
    }, 5000);
      //return false;
  }
  &lt;/script&gt;
  &lt;/html&gt;
  </code></pre>