i'd like to know a good way to add form to a dynamically created tables with jquery. i'v added a form in the folloqing way. but when i press the button the funcion in not called! I'm new to jquery so i've thing that there should be a better way to create the tables.
$("#aggiornaButton").click( function()
{
//alert('button clicked');
$.ajax({
url: 'Servizi/selectAllCoseDaFare.php',
data: "",
dataType: 'json',
success: function(data)
{
$( "#coseDaFareBody" ).empty();
var formElimina="<form action='' method='post' name ='eliminaForm' id='eliminaElementoSingolo' class='eliminaForm'>"
+"<fieldset>"
+"<input type='hidden' name='codID' id='codID' value='166'/>"
+"<button id='eliminaButtonSingolo' class='eliminaButtonSingolo'>elimina</button>"
+"</fieldset>"
+"</form>";
$.each(data.risultati, function(idx, obj) {
if (idx % 2 === 0) {var classe = "<tr><td>"}
else {var classe = "<tr class='miostile-odd'><td>"}
$( "#coseDaFareBody" ).append(
classe+obj.id+
"</td><td>"+(obj.dataInserimento || "")+
"</td><td>"+(obj.descrizione || "")+
"</td><td>"+(obj.dataScadenza || "")+
"</td><td>"+(obj.isUrgente || "")+
"</td><td>"+(obj.inseritoDa || "")+
"</td><td>"+(obj.assegnatoA || "")+
"</td><td>"+(obj.fattoDa || "")+
"</td><td>"+(obj.isCompletato || "")+
"</td><td>"+(obj.dataEsecuzione || "")+
"</td><td>"+formElimina+
"</td></tr>"
);
});
the function is.
$('.eliminaForm').submit(function(event) {
var $form = $(this);
var id = $('#codID', $form).val();
alert("prova prova prova.");
});
thank you. and sorry for my english
Aucun commentaire:
Enregistrer un commentaire