JavaScript Keycode 46 is DEL Function key or (.) period sign?
Decimal or dot key code on keypad is 190.. decimal on numpad is 110.
cheers..!!
@Mark Schultheiss' answer is really good, I'll add some more to it: when you need to push the DEL button on the keyboard outside the input element (that is when a text field loses focus) you have to intercept it. This can be done like so:
$("#selector-for-a-textbox, body").keydown(function(event){
if(event.keyCode==46){
// do something here
}
});
110 is the decimal key code, 46 is the DEL key.
For some fun: put this in to see what you hit! EDIT: added a focused event
/* handle special key press */
$(document).ready(function() {
function checkAKey(e) {
var shouldBubble = true;
switch (e.keyCode) {
// user pressed the Tab
case 9:
{
alert("Tab hit, no bubble");
shouldBubble = false;
break;
};
// user pressed the Enter
case 13:
{
alert("Enter");
break;
};
// user pressed the ESC
case 27:
{
alert("Escape");
break;
};
};
/* this propogates the jQuery event if true */
return shouldBubble;
};
$("*").keydown(function(e) {
return checkAKey(e);
});
});
OR
$(document).ready(function() {
/* handle special key press */
function checkFieldKey(e, me) {
var shouldBubble = true;
switch (e.keyCode) {
// user pressed the Enter
case 13:
{
$(me).blur();
$("#somewhereElse").focus();
shouldBubble = false;
break;
};
};
/* this propogates the jQuery event if true */
return shouldBubble;
};
/* user pressed special keys while in Selector */
$("#myField").keydown(function(e) {
return checkFieldKey(e, $(this));
});
});