I want to detect ‘enter’ key with respect to form without letting the form being submitted. How do I break this association?
document.forms[0].onkeypress = function (event) {
e = window.event ? window.event : event;
if (e.keyCode == 13) {
//actions to be taken
}
}
Though actions inside are taken properly, the page reloads upon completion.
Try to
return falseat the end of your function. Assuming that you’re handling the form submission already in asubmitevent callback.