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

138
Views
dynamically update the price

I need help with a JavaScript function that I don't know how to implement.
I need to make a store for a school project, and I need the price to dynamically update when adding / removing quantities.
Here is a picture of the store, the +/- button work correctly and all I just need to update the price in the add button.
I tried writing a function that will take the price below the name of the product and multiply it by the value in the quantity box but it's not working.

<button class="buttonshad buttonstyling bg-primary text-light mx-5">Add <a id="changingprice">$6.99</a></button>

picture

Here is my JavaScript function for increasing and decreasing:

  function increaseValue() {
    value = parseInt(document.getElementById('number').value, 10);
    value = isNaN(value) ? 0 : value;
    value++;
    document.getElementById('number').value = value;
  }

  function decreaseValue() {
    value = parseInt(document.getElementById('number').value, 10);
    value = isNaN(value) ? 0 : value;
    value < 1 ? value = 1 : '';
    value--;
    document.getElementById('number').value = value;
  }

Basically what I need is to update the price in the button when I add / remove quantity!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Here is an example for your inspiration.

let basePrice = 6.99;
document.querySelector("#qty").addEventListener("change", function(){
  document.querySelector("#changingprice span").innerText = (basePrice * this.value).toFixed(2)
})
#qty{
  width: 3em;
}
<input type="number" id="qty" min="0" value="0"/>
<button id="changingprice" class="buttonshad buttonstyling bg-primary text-light mx-5">Add $<span>0.00</span></button>

about 4 years ago · Juan Pablo Isaza Report
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!