jQuery:
JavaScript purocodice:$("#tuaTabella tr").click(function () { var valori = []; $(this).find("td").each(function () { valori[valori.length] = $(this).html(); }); alert(valori); });
Il tuo codice che errori ti da?codice:Array.prototype.forEach.call(document.querySelectorAll("#tuaTabella tr"), function (tr) { tr.addEventListener("click", function () { var valori = []; Array.prototype.forEach.call(this.children, function (td) { valori[valori.length] = td.innerHTML; }); document.getElementById("campo1").value = valori[0]; document.getElementById("campo2").value = valori[1]; document.getElementById("campo3").value = valori[2]; }); });
Edit Ups, preceduto... lascio per l'esempio senza jquery
Ri-edit Non ho visto che i dati ti servivano in un form...ho aggiornato il js

ho aggiornato il js
Rispondi quotando