Bootstrap FreeKB - JavaScript - Disable the Enter key on the keyboard
JavaScript - Disable the Enter key on the keyboard

Updated:   |  JavaScript articles

The following code will disable the Enter key on the user's keyboard. One example where this is practical is when data entered into an input field, such as a search engine, is programmed to disable data as the user types. The source of this code comes from http://webcheatsheet.com/javascript/disable_enter_key.php.

<script type="text/javascript">
function DisableEnterKey(evt) {
  var evt = (evt) ? evt : ((event) ? event : null);
  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
  if ((evt.keyCode == 13) && (node.type==\"text\")) {return false;}
}
document.onkeypress = DisableEnterKey;
</script>

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 071826 in the box below so that we can be sure you are a human.