DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Sr. Software Engineer, Apurba Technologies Inc. Yousuf has posted 1 posts at DZone. View Full User Profile

Disable Enter Key By Js

12.26.2009
| 2641 views |
  • submit to reddit
        //==================================================
// Disable Enter Key for a whole page. by javascript
//==================================================

<script type="text/javascript"> 
function stopRKey(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 = stopRKey; 
</script>