title: Submit form only if a function return true
body: <p>I need a way to submit the form ONLY if foo return true. I tried this code but it submits the form even if foo return false.</p>
  
  <pre><code>&lt;input type="submit" value="submit" onclick="return foo();" /&gt;
  &lt;script type="text/javascript"&gt;
      function foo() {
          // if... return true
          // else return false
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>If I use the onsubmit function, then it submits first. So it's not good in my case.</p>