HTML5 form input reacting to enter key

715 views Asked by At

I have looked through the available HTML and JS materials in print, and online, concerning the problem of "disabling the enter key" or at least eliminating the default of submitting a form when the enter key is pressed. My web page needs to ignore form submission until the appropriate button is pushed. For that matter, I would like to ignore any enter key depression while inside my form. I can send code samples if needed. I am new to this site and new to web development (Html-CSS-JS-JQ). I am an old linear programmer so please be merciful on your explanation. MANY thanks in advance.

1

There are 1 answers

0
Mark On

Really simple just do this:

$(form).keypress(function (e) {     
    var charCode = e.charCode || e.keyCode || e.which;
    if (charCode  == 13) {
        return false;
    }
});

Source