Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

114
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!