I have a dynamic section for products pulled from a database with an ajax call. Some results are single row and others are multi-rows. I have a placeholder row of HTML in the main page. this is used for initial data entry and can be deleted with java or add additional rows. My desired action is to pull from database via Ajax call count the rows returned and add/populate the results. I'm sure I'll need to delete the placeholder first, and re-create the HTML with each row returned. Also not sure how to fill JQuery element with the existing name field at item_desc[] for each element. I know id's are unique and class can be multiple so my only choice is the name element.
HTML:
<tr class="item-row">
<td class="item-name"><div class="delete-wpr"><textarea form ="testinsert" name="item_name[]">Hourly Rate</textarea>
<a class="delete" href="javascript:;" title="Remove row">X</a>
<a class="add-product" href="javascript:;" title="Add Product">A</a>
</div></td>
<td class="description"><textarea form ="testinsert" name="item_desc[]">Residential Rate: Consulting/Labor/Installs</textarea></td>
<td><textarea class="cost" form ="testinsert" name="item_cost[]">$95.00</textarea></td>
<td><textarea class="qty" form ="testinsert" name="item_qty[]">0</textarea></td>
<td><span class="price" form ="testinsert" name="item_price[]">$95.00</span></td>
</tr>
JQuery:
function populateTableRow(data, selectedProductAutonum) {
var invoices;
$.each(data, function() {
if (this.autonum == selectedProductAutonum) {
invoices = this;
return false;
}
});
$('[name="item_desc[0]"]').val(invoices.description);
$('[name="item_cost[0]"]').val(invoices.cost);
$('[name="item_qty[0]"]').val(invoices.quantity);
$('[name="item_price[0]"]').val(invoices.price);
}