Created
October 1, 2017 10:32
-
-
Save sarmadgardezi/300e35a36955172dd3dc38f2a97d5d22 to your computer and use it in GitHub Desktop.
How to disable Enter key on a form using JavaScript by Sarmad Gardezi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
<title>Disable Enter key using JavaScript</title> | |
<script type="text/javascript"> | |
function keypressAction(evt) { | |
var evt = (evt) ? evt : ((event) ? event : null); | |
if (evt.keyCode == 13) {return false;} | |
} | |
document.onkeypress = keypressAction; | |
</script> | |
</head> | |
<body> | |
<form name="frm" method="post"> | |
<p>Name: <input type="text" name="text1" /></p> | |
<p>Phone: <input type="text" name="text1" /></p> | |
<p>Email: <input type="text" name="text1" /></p> | |
<p><input type="submit" /></p> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment