I have the following function that reads the subtotal and adds the inpuesto that is defined in a hidden input and gives me the total, all that works well but I want to add a discount and send it so that when I enter it in the corresponding input, it adds up, but it does not do anything, the function is this.
function sumar(){
subtotal = 0;
$("#tbventas tbody tr").each(function(){
subtotal = subtotal + Number($(this).find("td:eq(5)").text());
});
$("input[name=subtotal]").val(subtotal.toFixed(2));
porcentaje = $("#impuesto").val();
impuesto = subtotal * (porcentaje/100);
$("input[name=impuesto]").val(impuesto.toFixed(2));
descuento = $("input[name=descuento]").val();
envio = $("input[name=envio]").val();
total = subtotal + impuesto - descuento + envio;
$("input[name=total]").val(total.toFixed(2));
}
and the inputs
<input type="text" class="form-control" placeholder="0.00" name="subtotal" readonly="readonly">
<input type="text" class="form-control" placeholder="0.00" name="impuesto" readonly="readonly">
<input type="text" class="form-control" placeholder="0.00" name="descuento" >
<input type="text" class="form-control" placeholder="0.00" name="envio" value="0.00" readonly="readonly">
<input type="text" class="form-control" placeholder="0.00" name="total" readonly="readonly">
the function gives me the value of the total and imposed subtotal, but does not do anything when I enter a value in discount or send. Greetings