1
I have an input that when inserted the matricula (identification) of a person, the rest of the table populates dynamically, and is automatically inserted another row of the table, which would work in the same way, insert the registration plate and the rest of the complete line again and so on. But only the first line works, the others do not, and I have no idea how to solve. Follow 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>
I think you could clear your code a little bit more and look like this: https://jsfiddle.net/jxbbvsa4/
– Sergio
Sergio thanks a lot, it worked out here.
– Silva Silva