Kill Event for Enter Key

[Total: 0    Average: 0/5]

This will kill the enter key event.

Head Code:

<script>
var isNS =document.appName=="Netscape"?true:false;
var isIE =document.all?true:false;
function keyHandler(e)
{
 var _ret=true;
 var _char=isIE?event.keyCode:e.which;
 alert("key press:" + _char);
 if(_char==13) /* enter key */
   _ret=false; /* kill event bubler */
 return _ret;
}
if(isNS)document.captureEvents(Event.KEYPERSS);/*for NS4*/
window.onkeypress=keyHandler;
</script>

Body Code:

<form name=f1 action="http://www.js-examples.com/" method=GET>
<input type=text name=var value="val">
<input type=submit>
</form>

Times Viewed: 6

Leave a Reply

Your email address will not be published. Required fields are marked *