Hello
I'm trying to retrieve the elements of a table and move to a jquery array that will be used in ajax
I create the td dynamically:
var newRow = $("<tr>");
var cols = "";
cols += '<td class="tdProductId" id='+ $("#product option").attr("id") +'>'+ $("#product option").text() +'</td>';
cols += '<td class="tdProductAmount">'+ $("input[name=amount]").val() +'</td>';
cols += '<td class="tdProductPrice">'+ $("input[name=price]").val() +'</td>';
cols += '<td class="tdProductTotal">'+ $("input[name=price]").val() * $("input[name=amount]").val() +'</td>';
cols += '<td>';
cols += '<a href="#" class="removeProduct">Remover</a>';
cols += '</td>';
newRow.append(cols);
$("#input_stock_product").append(newRow);
The problem is to recover the attr of one td and the text of the other and by in an array What I've tried to do, however, it does not create other indexes in the array, and ends up putting the values together:
var productsData = {
id_product: $(".tdProductId").attr("id"),
amount: $(".tdProductAmount").text(),
price: $(".tdProductPrice").text(),
total: $(".tdProductTotal").text()
};
This way it returns me an object, eg:
Object {id_product: "137", amount: "12", price: "11", total: "132"}