Can you show me how to capture the Tab key event in jQuery? I want to display an alert if a user clicks the Tab key while entering text in an input field.
I have tried using the following code but it's not working...
var myInput = document.getElementById("caseName");
if(myInput.addEventListener ) {
myInput.addEventListener('keydown',this.keyHandler,false);
} else if(myInput.attachEvent ) {
myInput.attachEvent('onkeydown',this.keyHandler); /* IE hack */
}
function keyHandler(e) {
alert("Hi")
var TABKEY = 9;
if(e.keyCode == TABKEY) {
this.value += " ";
alert("Tab")
if(e.preventDefault) {
e.preventDefault();
}
return false;
}
}