I have dynamic table that is created via script:
function addRow(tableID) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var colCount = table.rows[0].cells.length;
for(var i=0; i<colCount; i++) {
var newcell = row.insertCell(i);
newcell.innerHTML = table.rows[0].cells[i].innerHTML;
switch(newcell.childNodes[0].type) {
case "text":
if (newcell.childNodes[0].className === 'ui-widget ui-autocomplete-input') {
$(newcell.childNodes).autocomplete({
source: 'sites/produkt_suche.php'
});
}
newcell.childNodes[0].value= "";
break;
case "checkbox":
newcell.childNodes[0].checked = false;
break;
}
$(".ui-widget").focusout(function(){
var text = $(this).val();
$.ajax({
url: "sites/produkt_preis.php",
type: "POST",
dataType: "json",
data: { text: text },
success: function(result){
$("td:first-child").next().next().next().find("input").val($(this).innerHTML = result);
}
});
$.ajax({url: "sites/produkt_beschreibung.php",
type: "POST",
dataType: "json",
data: { text: text },
success: function(result){
newcell.lastChild.value = result;
}
});
});
}
}
I need to fill the last input inside the last td with a value I get via ajax and I also need to fill the second to last input inside the second to last td with an other value I get via ajax.
Currenty it is partially working even though not very good. The last input gets filled correctly, but it's done for all rows underneath as well (only last input).
The second to last input gets filled correctly, but it's done for all rows underneath and above (only second to last input)
Can you guys help me out? As you can see I am new to javascript and jQuery.