I have a function that is triggered by the onkeydown
event of a textbox. How can I tell if the user has hit either the backspace key or the del key?
You can use addEventListener or onkeydown property to detect a used pressed backspace key or not in JavaScript. Where Backspace key keycode is 8 and key is “Backspace”.
Try this:
document.addEventListener("keydown", KeyCheck); //or however you are calling your method function KeyCheck(event) { var KeyID = event.keyCode; switch(KeyID) { case 8: alert("backspace"); break; case 46: alert("delete"); break; default: break; } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With