Sum and Multiply dynamic input

Asked

Viewed 62 times

0

inserir a descrição da imagem aqui

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.

  • Got it, I’ll see another way here

  • 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;

  • Call me back (Nan)

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.