Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable enter key in html form? [duplicate]

Tags:

html

forms

enter

Quick question.

How do you disable Enter Key when you submit the form?

is there a way in PHP or Javascript?

like image 707
mistysnake Avatar asked Dec 08 '22 10:12

mistysnake


2 Answers

$('input').on('keydown', function(event) {
   var x = event.which;
   if (x === 13) {
       event.preventDefault();
   }
});
like image 182
CRABOLO Avatar answered Dec 31 '22 03:12

CRABOLO


Simplest solution:
Don't use a submit-button in the form, but use a normal button.
Using Enter/Return acts as pressing the Submit button

By the way, I personally hate forms that don't allow me to use Enter/Return.
It just feels annoying and slow if you need to grab your mouse to press Submit

Also don't forget that using Enter/Return to submit a form is part of its accessibility. By declining users to submit a form this way, you're negatively impacting people in need of these accessibility features.

like image 28
BlueCacti Avatar answered Dec 31 '22 03:12

BlueCacti