View Full Version : onkeypress doesnt detect delete key
mayank123
02-10-2006, 05:03 PM
hello
I need to call a function when the delete key is pressed but the onkeypress event doesnt fire at all when i hit delete key, for all other keys it works except insert, home, pageup and 3 other keys below them.
does anyone know how to get around this problem.
Mayank
Philip M
02-10-2006, 05:34 PM
<HTML>
<HEAD>
<SCRIPT language="JavaScript">
IE5=document.all? 1:0
function displayKeycode(e)
{
whKey = !IE5? e.which:event.keyCode; // check for NS4 and NS6
alert (whKey);
}
</SCRIPT>
</HEAD>
<BODY>
<CENTER>
<FORM NAME="f">
<TEXTAREA NAME="txt" COLS="30" ROWS="4" onKeyDown="displayKeycode (event)" >Type some test characters here </TEXTAREA>
</FORM>
</CENTER>
</BODY>
</HTML>
The ASCII value of delete is 46.
onKeyPress does not detect the delete key for some reason.
liorean
02-10-2006, 05:56 PM
I think I explained the reason for this behavior in an earlier post here.
Essentially, the keypress event would be more appropriately named characterentry. It detects not which key is being pressed, but which character is entered into the document.
felgall
02-10-2006, 09:47 PM
Some key presses are processed by the operating system or the browser and therefore don't reach the web page.
Also the function should not be testing document.all since that has no relevance to what you are testing for.
function displayKeycode(e)
{
whKey = e? e.which:event.keyCode; // check for which is supported
alert (whKey);
}
mayank123
02-12-2006, 05:09 AM
thank you so much guys...
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.