I have the following code:
<div class="postcode">
<div>
<input type="text" maxlength="4">
</div>
<div>
<input type="text" maxlength="4">
</div>
</div>
I need Jquery to automatically focus on the next input once 4 characters have been entered. I have tried the following, but this only works if the inputs are next to each other:
$(".postcode input").keyup(function () {
if (this.value.length == this.maxLength) {
$(this).next('.postcode input').focus();
}
});
This also means that when I shift+tab, it keeps focusing on the next div.
Lastly, I also need it to go back to the first input if the user deletes all characters from the second input.