How to disallow Enter key on a form using JavaScript

You may have come across situations where you don’t want the HTML form to submit on pressing Enter key. The reason could be that you may have a long form which the user needs to fill and most users may have the habit of pressing Enter key when trying to move to the next field.

We will use JavaScript for this purpose. There is anĀ onkeypress event we will use for this purpose. We can setup a callback function against this event and check for the Enter key ASCII code and return false so that the action does not take place.

Hope the above helped.

If you would like to download the whole file with the code then please download
Disable Enter key using Javascript.

Be the first to comment

Leave a Reply