onsubmit attribute: some gotchas

Posted 2015-02-04

  • Don’t forget the return: it’s onsubmit="return someFunction()" not onsubmit="someFunction()"
  • If you are relying on an external javascript file to provide someFunction(), the function mustn’t be wrapped in anything else. This means, no $(document).ready() or the like. As a result, the external script needs to go just before the closing </body> tag rather than in the <head> in order for everything to load in the right order.