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

113
Visualizações
javascript - sum of values on input change

I'm modifying a draft website which is basically mde by storing data in local storage and fetching and rendering it. On the cart.html page input are created dynamically, depending upon how many packages are added in the cart.

There are 2 prices, one which is package's price (works totally fine) and the other one is Total price of all the items in cart, which doesn't seem to update and adds on values to the previous value. I'm not sure what I'm doing wrong but any help would be great!

I'm also attaching stackblitz to get better understanding of my application. Please readme if you want instructions

cart.html

        <div class="totalPrice">
            <table>
                <tr>
                    <td>Total Price</td>
                    <td id="totalPriceCount" data-total=""></td>
                </tr>
            </table>
        </div>
      

JS: (Don't really have idea how to achieve)

$(".myInput").on('input', function () {
            varCurrentVal = this.value;
            if (varCurrentVal == 0) {
                return;
            }
            var closestSibAttr = $(this).parent().parent().find("#quantityBasedPrice").attr("data-val");
            $(this).parent().parent().find("#quantityBasedPrice").html(varCurrentVal * closestSibAttr).attr("data-total", varCurrentVal * closestSibAttr);

// code to update #totalPriceCount to sum all the values into the Total Price
        })

Stackblitz: https://stackblitz.com/edit/web-platform-8cynxp?file=turkey.html

about 4 years ago · Santiago Gelvez
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