I have an input that when you insert the enrollment (ID) of a person, the rest of the table populate dynamically, and another row of the table is automatically inserted, which would work the same way, the enrollment and the rest of the row complete again and so on. But only the first line works, the others do not, and I have no idea how to solve it. Here is the code:
<script type="text/javascript">
$(document).ready(function(){
var x = 0;
$(document).on('blur', 'input[name="matBusca['+ x +']"]' ,function(){
var y = x + 1;
$('#listas').append('\
<tr><td><input type="text" name="matBusca['+ y +']"></td>\
<td><input type="text" name="nomeBusca['+ y +']"></td>\
<td><input type="text" name="cargoBusca['+ y +']"></td>\
<td><input type="text" name="clpdBusca['+ y +']"></td>\
');
$("input[name='matBusca["+ y +"]']").focus();
var $nome = $("input[name='nomeBusca["+ x +"]']");
var $cargo = $("input[name='cargoBusca["+ x +"]']");
var $clpd = $("input[name='clpdBusca["+ x +"]']");
$nome.val('Carregando...');
$cargo.val('Carregando...');
$clpd.val('Carregando...');
$.getJSON(
'function.php',
{ matBusca: $( this ).val() },
function( json ){
$nome.val( json.nome );
$cargo.val( json.cargo );
$clpd.val( json.clpd );
}
);
x++;
});
});
</script>