1
I have a page that generates a form dynamically
using append('texto html');
These inputs that I Gero after loading the page completely, I cannot by them invoke functions js created in the page ready, ie before the inputs exist.
ex: create a form with name and Cpf and save button using append.
In my script there is already a method salvar(){}
and when I create the button on onclick, I call save(), but it doesn’t work. I think because the input was created after the page load. There is something you can do to fix this?
<script type='text/javascript'>
$( document ).ready(function() {
$('#confirm_edit').click(function(){
$('#form_execucao').append('<br class=\"campos bts\" /><br class=\"campos bts\" />');
$('#form_execucao').append('<label id=\"bt_print\" name=\"bt_print\" onclick=\"pt()\" style=\"margin-left:5px; height:30px; font: normal 13px Verdana, Arial, Times;\" for=\"salvar\" class=\"btn btn-primary campos bts\"><i class=\"glyphicon glyphicon-print\"></i> Imprimir</label>');
$('#form_execucao').append('<label id=\"bt_salvar\" name=\"bt_salvar\" onclick=\"sv()\" style=\"margin-left:10px; height:30px; font: normal 13px Verdana, Arial, Times;\" for=\"salvar\" class=\"btn btn-info campos bts\"><i class=\"glyphicon glyphicon-floppy-disk\"></i> Salvar</label>');
});
function pt(){
alert('imprimindo');
}
function sv(){
alert('salvando');
}
});
</script>
I partially understood Hugo, can share the relevant code snippets?
– BrTkCa