Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
126
rated 0 times [  128] [ 2]  / answers: 1 / hits: 23007  / 11 Years ago, thu, march 21, 2013, 12:00:00

is there a cross-browser solution to disable 'tab' on a input type='text' ?



<input type='text' />


Pressing 'tab' moves you to the next 'focusable' component (for example a button)



I want instead 'tab' to do something else.
For example
Even in a google search tab is just used to autocomplete the suggested text instead of moving you to the next focusable component...



thanks


More From » jquery

 Answers
8
document.querySelector('input').addEventListener('keydown', function (e) {
if (e.which == 9) {
e.preventDefault();
}
});


Depends on how cross-browser you are talking though, as the above only supports IE9 (and other modern browsers).



http://jsfiddle.net/ExplosionPIlls/YVUzz/



IE8- use attachEvent instead of addEventListener and e.keyCode instead of e.which, and there is no preventDefault, but you can use return false.


[#79435] Wednesday, March 20, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sonja

Total Points: 541
Total Questions: 113
Total Answers: 114

Location: Anguilla
Member since Sun, Jan 29, 2023
1 Year ago
sonja questions
Mon, Nov 30, 20, 00:00, 4 Years ago
Sun, Oct 11, 20, 00:00, 4 Years ago
Thu, May 21, 20, 00:00, 4 Years ago
Sun, Nov 10, 19, 00:00, 5 Years ago
Mon, Aug 26, 19, 00:00, 5 Years ago
;