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

141
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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