When the numbers are typed, they automatically go to the next input. But how do I get it back to the previous input when I delete it from the input?
(function() {
var inputs = $("#passForm input");
inputs.each(function(i, item) {
$(item).keyup(function() {
if ($(this).val().length == $(this).attr('maxlength') && inputs[i + 1]) {
if (inputs[i + 1]) {
inputs[i + 1].focus();
}
}
});
});
}());
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form action="" role="form" method="post" id="passForm">
<input type="text" class="passInput" autofocus name="pass[]" maxLength="1" autocomplete="off" size="1" min="0" max="9" required pattern="[0-9]{1}" />
<input type="text" class="passInput" name="pass[]" maxLength="1" size="1" autocomplete="off" min="0" max="9" required pattern="[0-9]{1}" />
<input type="text" class="passInput" name="pass[]" maxLength="1" size="1" autocomplete="off" min="0" max="9" required pattern="[0-9]{1}" />
<input type="text" class="passInput" name="pass[]" maxLength="1" size="1" autocomplete="off" min="0" max="9" required pattern="[0-9]{1}" />
<input type="text" class="passInput" name="pass[]" maxLength="1" size="1" autocomplete="off" min="0" max="9" required pattern="[0-9]{1}" />
<input type="text" class="passInput" name="pass[]" maxLength="1" size="1" autocomplete="off" min="0" max="9" pattern="[0-9]{1}" /><br>
<button type="submit" class="btn btn-lg btn-primary" style="margin: 30px 0 50px;"> submit
</button>
</form>