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

162
Visualizações
Calling a javascript onclick function

I have some code on a page for a cart system with the following:

<div class="number-input">
<button onclick="this.parentNode.querySelector('input[type=number]').stepDown();preventDefault(); updateCartItems('2371') " ></button>
<input class="quantity" id="addQuantity-2371"  min="1" name="cart_quantity[]" value="5" step="1" type="number">
<button onclick="$(this).prev()[0].stepUp();preventDefault(); updateCartItems('2371') " class="plus">
</button>
</div>

I am looking to call a function, in addition to changing the displayed value:

function updateCartItems(itemId) { // begin document ready
    var products_id = parseInt(itemId);
    var quantity = document.getElementById('addQuantity-' + itemId);
    if (quantity) {
      var cart_quantity = parseInt(quantity.value);
    } else {
      var cart_quantity = parseInt(1);
    };
    $.ajax({
      url: 'ajax_add_saved_product.php',
      method: "post",
      dataType : "html",
      data: {cart_quantity, products_id},
      success: function (response, textStatus, jqXHR) {
         alert(response);
         $('#cartData').html(response);
         update_cart_total();
         update_free_products();
         update_shipping_estimate();
      },
       error: function (jqXHR, textStatus, errorThrown) {
         alert(xhr.responseText);
        },
    });
 };

Issue is that I am not calling the updateCartItems function. Am I doing the call correctly?

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