On Mar 14, 10:15 am, "Sorrow" <jcbo...@yahoo.comwrote:
If you have an onsubmit event handler defined for a form, it doesn't seem to
trigger if you manually call the .submit() method of the form object.
Most browsers work that way, but some will fire the submit event when
the form's submit method is called programatically (e.g. Opera 7,
perhaps later versions too, I can't test it right now).
Is
there any way you can make sure that code is executed?
Call it with the function that calls submit. You will need to deal
with stopping the onsubmit handler from firing twice in some browsers
- perhaps if it runs successfully, you can remove it before calling
submit().
<script type="text/javascript">
function doSubmit(el) {
var form = el.form;
if (typeof form.onsubmit == 'function') {
if (form.onsubmit() !== false) {
form.submit();
}
}
}
</script>
<form onsubmit="alert('hey'); return false;">
<div><input type="button" value="submit onclick"
onclick="doSubmit(this);"></div>
</form>
--
Rob