Disable form submission via Enter key on only _some fields

Posted by justSteve on Stack Overflow See other posts from Stack Overflow or by justSteve
Published on 2010-05-08T12:21:22Z Indexed on 2010/05/08 12:28 UTC
Read the original article Hit count: 134

Filed under:
|

I want to retain the conventional 'form submits when i press Enter' behavior because users are familiar with. But by reflex, they often hit enter when they finish with a text input box - but before they are actually done with the complete form.

I'd like to hijack the Enter key only when then focus is on a certain class of input.

Looking Related Questions this looks like what I'm looking for:

if (document.addEventListener) {
    document.getElementById('strip').addEventListener('keypress',HandleKeyPress,false);
} else {
    document.getElementById('strip').onkeypress = HandleKeyPress;
}

but the if (document.addEventListener) { is unfamiliar.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about webforms