If you can't add ids to your inputs you need to find different selectors for those attributes. If you are planning to send this data you probably have a name for those tags. Then you can match next input by name using following selector:
$('input[name=nextInputName]')
Otherwise you can always find next element using combination of children()
and parent()
method calls in order to traverse from current input to another.
I personally think that the simpliest solution would be to assign ids, even in jQuery if you can't do it in HTML and this will make autofocusing easier.
var counter = 0;
$('input').each(function () {
if (!$(this).attr('id')) {
$(this).attr('id', 'autofocus' + counter);
counter += 1;
}
});
You can change the selector to skip some of the element you don't want to have autofocus feature.
You can then even write down autofocus yourself in few lines:
$('input[id^=autofocus]').keyup(function () {
if ($(this).val().length === $(this).attr('maxlength')) {
var id = $(this).attr('id').match(/^autofocus(\d+)$/[1];
var nextId = Number(id) + 1;
$('#autofocus' + nextId).focus()
}
});