get keycode by javascript

<input type=”text” onKeyUp=”getkeycode(event)”>

<script>
function getkeycode(eventhandler)
{
alert(“Key Code Is :”+eventhandler.keyCode);
}
</script>

You may also use this sort of function to disable certain keys, by adding a void(0) in the function as shown. This essentially tells the page to cancel the last event, e.g. the pressing of that certain key. In the example below, the key that is disabled is the enter key.

<script language=”JavaScript”>
document.onkeydown = checkKeycode
function checkKeycode(e) {
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
if(keycode == 13){
void(0);
}
}
</script>

Press any key to determine the javascript key code of that key. This is a simple script:

<script language=”JavaScript”>
document.onkeydown = checkKeycode
function checkKeycode(e) {
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
alert(“keycode: ” + keycode);
}
</script>

Similar Posts

Leave a Reply

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