When putting together a ticket, I calculate the subtotal and taxes, etc.
And I have two tables: one with the articles and another one with totals. How do I assign the value of the sum of the subtotals to a cell in the total table:
success: function(data){
if (jQuery.isEmptyObject(data)){alert("sin articulos");}else{
var subtotal = 0;
$.each(data, function(i, item) {
var newRow =
"<tr>" +
"<td>" + item.id + "</td>" +
"<td>" + item.cantidad + "</td>" +
"<td>" + item.nombre + "</td>" +
"<td>" + item.precio + "</td>" +
"<td>" + item.subtotal + "</td>" +
"</tr>";
subtotal=subtotal + item.subtotal;
$(newRow).appendTo("#ticket tbody");
});
The subtotal shows it to me in a perfect alert. here the sun:
<div class="row" style="vertical-align: left;">
<table class="totales">
<thead>
<tr>
<th>Subtotal.:</th> <td><p id="sub"></p></td>
</tr>
<tr>
<th>IVA(21).:</th><td id="IVA">10</td>
</tr>
<tr>
<th>Total.:</th><td id="total">10</td></tr>
</thead>
</table>
For example, identify the td with id sub to assign the subtotal