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

228
Views
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?

over 4 years ago · Santiago Trujillo
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!