I\'ve got four inputs that each take one number. What I want to do is set the focus automatically to the next input once the number has been set. They all have the class \"i
After searching and developing I end up in a crossbrowser snippet which makes it possible to focus the next input field with same class depending on maxlength (tested with 1 character) also with the ability to focus back via backspace button:
Javascript (jquery):
var codeCharInput = 'input.code-char';
$(codeCharInput+':first').focus();
$(codeCharInput).keyup(function(e) {
if ((e.which == 8 || e.which == 46)) {
$(this).prev(codeCharInput).focus().val($(this).prev().val());
} else {
if (this.value.length == this.maxLength) {
$(this).next(codeCharInput).focus();
}
}
});
HTML: