Hello
Does anyone know a good crossbrowser script that prevents forms from being submitted by hitting enter key?
What I need is a script that makes it unnecessary to add javascript to form elements.
I've used this one but it doesn't seem to work anymore for some unknown reason :
Code:
var fnav = window.Event ? true : false;
if (fnav) {
window.captureEvents(Event.KEYDOWN);
window.onkeydown = NetscapeEventHandler_KeyDown;
} else {
document.onkeydown = MicrosoftEventHandler_KeyDown;
}
function NetscapeEventHandler_KeyDown(e) {
if (e.which == 13 && e.target.type != 'textarea' && e.target.type != 'submit') { return false };
return true;
}
function MicrosoftEventHandler_KeyDown() {
if (event.keyCode == 13 && event.srcElement.type != 'textarea' && event.srcElement.type != 'submit')
return false;
return true;
}
Thanks a lot!