Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

88
Visualizações
Total increments unexpectedly in sum of fields

Dynamic added inputs each creates a total

Q. How can i reflect an accurate total of all totals from the inputs

(totals are the product of the first two columns/fields for each row)

When adding the totals, the total field is not incrementing for all fields as expected enter image description here the total at the bottom should show a sum of all totals from the table, yet is showing only the last total enter image description here

https://jsfiddle.net/ariia/g81kqro2/110/

$('body').on('change','.rowinput' , function(){
            var rowid=$(this).data('rowid');
           // alert(rowid);
             rowTotal(rowid);
          })
          
          function rowTotal(sumthis) {
        
            units = $('#row-'+sumthis+'-units').val()
            unitprice = $('#row-'+sumthis+'-unit-price').val()  
            rowtotal=units*unitprice
        
            $('#row-'+sumthis+'-total').val(rowtotal)
            invtotal(rowtotal)
        
          }
      function invtotal(totalz) {
           var totalx=0
            totalx = totalx+=totalz
        
        //alert(totalx)
        //return totalx
        $('#total>span').text(totalx)
      }

When placing the variable outside and not init to 0 each row, i get the desired effect with true totals, until i change the row total, say to a smaller total, the incorrect value then shows.

enter image description here

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda