If you cannot add identifiers to your inputs, you need to find different selectors for these attributes.
You probably have a name for these tags if you plan on sending this data. Then you can match the following input by name using the following selector:
$('input[name=nextInputName]')
, children() parent(), .
, , jQuery, HTML: .
var counter = 0;
$('input').each(function () {
if (!$(this).attr('id')) {
$(this).attr('id', 'autofocus' + counter);
counter += 1;
}
});
, , .
:
$('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()
}
});