0
I have this function that multiplies qnt * vlor = subtotal
in a dynamic table.
But it only does the calculation on the first line. I would also like to pull the total sum so subtotal.
I found that link but I wanted something simpler.
Summing up
<script type="text/javascript">
$("#tbodyCotacao").on("blur keyup", function (event) {
calcular()
});
function calcular(){
var valor1 = parseInt(document.getElementById('pqnt').value, 10);
var valor2 = parseInt(document.getElementById('pvlr').value, 10);
document.getElementById('ptotal').value = valor1 * valor2;
}
</script>
I won’t be able to formulate an answer now, but you won’t be able to use Ids on repeated elements, Ids are unique. And you will also need to understand how delegation of events works (this answer has a good explanation), because its events need to be heard by inputs existing and by the _ inputs_ that will exist.
– fernandosavio
Got it, I’ll see another way here
– frodrigues
I tried to do so : var vQnt = $(this). Parent(). Parent(). find('input[id ="pqnt"]'). val(); var vVlr = $(this). Parent(). Parent(). find('input[id ="pvlr"]'). val(); const Quant = parseint(vQnt); const value = parseint(vVlr); Alert(Quant +'/'+ value) // Document.getElementById('ptotal'). value = Quant * value;
– frodrigues
Call me back (Nan)
– frodrigues