Reputation: 47
On a Page with many form-fields I wanna set specific ones to tabindex="-1". But when the user checks a checkbox the fields with tabindex="-1" should get reached by a tabular as usual. How to do this? Tabindex="auto" & tabindex="" don't work.
My Javascript:
function setTabindex(checkboxChecked) {
var tabindexValue = cbChecked ? '' /* <-- what should I enter here? */ : '-1';
var noTabindexElements = document.querySelectorAll('input[data-notabindex]');
for (var i = 0; i < noTabindexElements.length; i++) {
noTabindexElements[i].setAttribute('tabindex', tabindexValue);
}
}
Upvotes: 3
Views: 4330
Reputation: 1
For all those who are looking for something better, you can also do this:
input.setAttribute("tabindex", null);
Upvotes: 0
Reputation: 2599
According to MDN & HTML specs this should work, but I haven't tested it:
function setTabindex(checkboxChecked) {
var tabindexValue = cbChecked ? 0 : -1;
var noTabindexElements = document.querySelectorAll('input[data-notabindex]');
for (var i = 0; i < noTabindexElements.length; i++) {
noTabindexElements[i].tabIndex = tabindexValue;
}
}
Upvotes: 2