I have the following simple javascript code that processes the return key, I don’t want to submit the form when the return key is pressed in the text box.
All this works fine, but in Firefox, if I show a warning message, it stops working and the form starts receiving, while the exact code without a warning message works fine and stops sending the form. I don’t understand why the notification spoils the party.
$("document").ready(function () {
$("#input1").keydown(OnKeyDown);
});
function OnKeyDown(e) {
if (e.keyCode == 13) {
stopBubble(e);
return false;
}
}
function stopBubble (e) {
if (e && e.stopPropagation)
e.stopPropagation();
else
window.event.cancelBubble = true;
}
<input type="text" id="input1" value="">
source
share