Reputation: 655
I would like to select an suggestion entry in my input field when I press the TAB key (typical Google behaviour). My Problem is that when I press the TAB key, Firefox sets the focus on the tab in which my application is open, but my concern is that the focus stays on my input field. My code looks something like:
$("#search-input").keyup(function (event) {
switch (event.keyCode) {
case 9:
{
// tab key is pressed
event.preventDefault();
foo();
bar();
//set focus back to the input (dont works)
$("#search-input").focus();
break;
}
default:
baz();
}
});
thanks!
[EDIT] Solved! The solution is very easy: Firefox reacts already on keydown
event so I needed just to put the same behaviour in the keydown event.
Upvotes: 0
Views: 652
Reputation: 655
Firefox reacts already on keydown event so I needed just to put the same behaviour in the keydown event.
$("#search-input").keydown(function (event) {
switch (event.keyCode) {
case 9:
{
// tab key is pressed
event.preventDefault();
foo();
bar();
//set focus back to the input (dont works)
$("#search-input").focus();
break;
}
default:
baz();
}
});
Upvotes: 2