3
How to select an element by some type attribute (type, for, value) as in jQuery ex: [type=text]?
I wanted to make a function to jump fields in an automatic form...I wanted to do like this, take the tabindex of the current element and make the element tabindex + 1 wins Focus().
Follow the script to skip fields when they are completed with the help of Sérgio:
function pulacampo(id){
var campo = document.getElementById(id);
var proximo = campo.tabIndex + 1;
var proximoElemento = document.querySelector("[tabindex='" + proximo + "']");
if (campo.value.length == campo.maxLength){
proximoElemento.focus();
}
}
You just need to set the tabindex of the fields and insert the function into the keypress/down/up
It’s like jQeury but using the
querySelector
. Foreheaddocument.querySelector('[type="text"]');
– Sergio