Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sarmadgardezi/300e35a36955172dd3dc38f2a97d5d22 to your computer and use it in GitHub Desktop.
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
<!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