function resta(numr, numr1, resultador) {
resultador.value = (numr - numr1);
}
function calculo(cantidad, precio, inputtext, totaltext) {
gndtotal = totaltext.value - inputtext.value;
subtotal = (precio * cantidad);
inputtext.value = subtotal;
total = eval(gndtotal);
totaltext.value = total + subtotal;
}
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<tr id="panela">
<td>
<label class="title">Panela:</label><br>
<label class="num">5</label>
</td>
<td>
<input type="hidden" id="PanelaIn" name="PanelaIn" value="<?php echo $ver[3]; ?>">
<input type="number"
class="form-control form-control-lg"
id="Panela" name="Panela" placeholder="Saldo"
required onChange="resta(PanelaIn.value,this.value,resPanela);"><br>
<input type="number"
class="form-control form-control-lg"
id="resPanela" name="resPanela"
onchange="calculo(this.value,preciopanela.value,RPanela,total);">
</td>
<input type="hidden" id="preciopanela" value="150">
<td>
<input type="text"
class="form-control form-control-sm"
id="RPanela" name="RPanela" value="0" readonly>
</td>
I have two functions, subtraction and calculation. each individual function works well.
The problem I have is that the calculation function does not recognize the variable "quantity" that is generated automatically by the subtraction function.
I do not know if it's the best option for this calculation. Thank you very much for your time