Friday, December 11, 2009

Disable enter key using java script

Use the below code to disable enter key. You can also used this to disable un wanted keys,too. Just add more combination of keys after "evt.keyCode == 13".
<html>
<head>
<script language=javascript 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) {return false;}
}

document.onkeypress = stopRKey;
-->
</script>
</head>

<body>
<textarea rows="5"></textarea>
</body>
</html>

No comments:

Post a Comment