by Tim Hunt.
Well, the best solution is to avoid polluting the HTML with attribues like onsubmit just to make your JavaScript work.
Instead, use JavaScript like form.addEventListener('submit', myFunction); (or the wrapper around that provided by a library like YUI).
To get Moodle to run your JavaSript, look at $PAGE->requires->js_init_call() in Moodle code.