Colleagues will be brief, I have a table that is filled by a foreach with an array that is filled from the database, by jquery I use the button more to add the product value and fence me calculating the total, if I press the menu it is subtracting the price, it is a table with more than 1 record but for some reason only considers the first row, the second on does not consider my code jquery is as follows:
$('#mas').click(function () {
var cantidad = $('#cantidad').val();
var suma = parseInt(cantidad) + 1;
var precios = $('#precios').val();
var total = parseInt(precios) * suma;
// alert(total);
$('#cantidad').val(suma);
$('#total').val(total);
console.log(precios);
});
$('#menos').click(function () {
var cantidad = $('#cantidad').val();
var precios = $('#precios').val();
var suma = parseInt(cantidad) - 1;
var total = $('#total').val();
var total2 = total - precios;
if (suma >= 0) {
$('#cantidad').val(suma);
$('#total').val(total2);
}
console.log(precios);
});
and my table is the following (I put it hard since I did not see any sense add the foreach):
<table id="TablaCilindro" class="table table-responsive table-bordered">
<thead>
<tr>
<th>Agregar</th>
<th>Cilindro</th>
<th>Restar</th>
<th>Cantidad</th>
<th>Precio</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="button" value="+" id="mas1"></td>
<td>producto 1</td>
<td><input type="button" value="-" id="menos"></td>
<td><input type="text" id="cantidad" value="0" class="btn btn-sm col-sm-6"></td>
<td><input type="tex" id="precios" value="20500" class="btn btn-sm col-sm-12"></td>
<td><input type="text" id="total" value="0" class="btn btn-sm col-12"></td>
</tr>
<tr>
<td><input type="button" value="+" id="mas"></td>
<td>producto 2</td>
<td><input type="button" value="-" id="menos"></td>
<td><input type="text" id="cantidad" value="0" class="btn btn-sm col-sm-6"></td>
<td><input type="tex" id="precios" value="20000" class="btn btn-sm col-sm-12"></td>
<td><input type="text" id="total" value="0" class="btn btn-sm col-12"></td>
</tr>
</tbody>
</table>
How can I get it to take each row with its corresponding price?
beforehand thank you very much