0

Si tengo varios input que con el onkeyup pasa automaticamente a otro ¿cómo hago para que al borrar regresa automaticamente al input anterior?

Aquí un ejemplo varios input que con el onkeyup pasa automaticamente a otro ¿cómo hago para que al borrar regresa automaticamente al input anterior?

<input type="text" name="da" maxlength="1" max="9" min="0" required 
    onkeyup="if (this.value.length == this.getAttribute('maxlength')) input2.focus()"  autocomplete="off">
    <input type="text" id="input2" name="db" maxlength="1" max="9" min="0" required 
    onkeyup="if (this.value.length == this.getAttribute('maxlength')) input3.focus()" autocomplete="off">
    <input type="text" id="input3" name="dc" maxlength="1" max="9" min="0" required 
    onkeyup="if (this.value.length == this.getAttribute('maxlength')) input4.focus()" autocomplete="off">
   

1 respuesta 1

0

Simplemente, comprueba la longitud del contenido del input, si después del keyup la longitud es 0, le pasas el foco al anterior. Te dejo el ejemplo.

<input type="text" id = "input1" name="da" maxlength="1" max="9" min="0" required 
    onkeyup="if (this.value.length == this.getAttribute('maxlength')) input2.focus()"  autocomplete="off">
    <input type="text" id="input2" name="db" maxlength="1" max="9" min="0" required 
    onkeyup="if (this.value.length == this.getAttribute('maxlength')) input3.focus(); if (this.value.length == 0) input1.focus();" autocomplete="off">
    <input type="text" id="input3" name="dc" maxlength="1" max="9" min="0" required 
    onkeyup="if (this.value.length == this.getAttribute('maxlength')) input4.focus(); if (this.value.length == 0) input2.focus();" autocomplete="off">

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.