You return false for the keydown event, not for the submit event. Thus, the submission of the form will continue without change.
Perhaps you can stop the event in the keydown handler, which may be the most elegant solution - I donβt know, maybe someone will come up with a proposal for this.
Meanwhile, as another parameter, you can set the Do Not Submit Form flag in the keydown event, which you then check on the submit form.
Unconfirmed, but should work somewhere in these lines:
// in the `keydown` function if (key == 13) { alert('Test text.'); this.form.do_not_submit = true; ...... <form onsubmit="submit()"...> .... function submit() { if (this.do_not_submit == true) return false; }
I am not 100% OTOH sure whether it is possible to assign properties to these DOM elements ( this.do_not_submit ), but I am sure that it is.
source share