Is there a way to disable the "tab" for input type = "text"?

Is there a cross-browser solution to disable the "tab" for input type = "text"?

<input type='text' />

By clicking the “tab”, you will go to the next “custom” component (for example, to the button)

I want to do something else instead of 'tab'. For example, Even on the search tab, Google is simply used to autocomplete the proposed text, and not to go to the next custom component ...

thank

+5
source share
3 answers
document.querySelector('input').addEventListener('keydown', function (e) {
    if (e.which == 9) {
        e.preventDefault();
    }
});

Depending on how you are talking with the cross-browser, since the above only supports IE9 (and other modern browsers).

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

IE8 - attachEvent addEventListener e.keyCode e.which, preventDefault, return false.

+10

jQuery -

HTML

<input type="text" id="myField1" onkeydown="return stopTab(event);" />

JS -

function stopTab( e ) {
    var evt = e || window.event
    if ( evt.keyCode === 9 ) {
        return false
    }
}
+2

Yes, check if the tab key has been pressed, and if so, returns false:

<form class='noTab'>
    <input type="text" />
    <input type="text" />
    <select>
        <option>a</option>
        <option>b</option>
    </select>
    <textarea>
    </textarea>
</form>

jQuery('.noTab').find('input,select,textarea').keydown(function (e) {
    if (e.which === 9) {
        return false;
    }
});

jQuery will allow working with outdated browsers.

http://jsfiddle.net/JxMhY/

Two forms are displayed on this script: one with the "noTab" class and one without it, since the tab / shift + tab is useful for many forms, but not for those that have a special "tab" action.

+1
source

All Articles