What you seek is to call focus
of an element. For example:
var select = document.querySelector('select');
select.addEventListener('change', function() {
var input = document.querySelector('input[name="' + this.value + '"]');
if (input) input.focus();
});
In this example each time you select change it will look for an input with the name that was selected in select. If you find it you put it in focus.
For cases where you have an input limit just count the size of the string in the input and pass to the next input when this condition is checked. An example would be:
var inputs = document.querySelectorAll('input');
[].forEach.call(inputs, function(el) {
if (el.dataset && el.dataset.length) {
var max = parseInt(el.dataset.length, 10);
el.addEventListener('keyup', function() {
if (this.value.length >= max) focusNext(this, inputs)
});
}
});
function focusNext(el, els) {
var match;
for (var i = 0; i < els.length; i++) {
if (match) {
els[i].focus();
break;
}
match = els[i] == el;
}
}
Thanks @Julyanofelipe, it worked, but as Sergio complemented his reply I marked it as correct.
– Raylan Soares
Beauty, thanks @Raylansoares
– Julyano Felipe