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

194
Views
How do I pass a argument in this function

I am working On a shopping cart function, but I want to send product id's to This javascript part.

    $(".qtybutton").on("click", function(){
        var $button = $(this);
        var oldValue = $button.parent().find("input").val();
        var id = $button.parent().find("key").val();
        if ($button.text() === "+") {

            var newVal = parseFloat(oldValue) + 1;
            $.post("cart_session.php", {action:'call_this', newVal: newVal },
            function(data) {
                $('#results').html(data);
            });
        } 

This is the html part.

<div class="dec qtybutton">-</div>
<form method="POST">
<input class="cart-plus-minus-box" type="integer" value="2" disabled>
</form>
<div class="inc qtybutton">+</div>

I want to will pass argument with php ex:- function(<?= $key?>), I want to know how do I do this?

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

0

I would suggest putting the product id in the form field as a data attribute. That way you can always associate the product id with the quantity.

$(".qtybutton").on("click", function() {
  let $button = $(this), $inc = $button.closest('.q-cont').find("input")
  let newVal = Math.max(0,+$inc.val() + +$button.data('inc'))
  $inc.val(newVal);
  let id = $inc.data('productid');
  console.log('newVal:', $inc.val(), 'id:', id)
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class='q-cont'>
  <div class="dec qtybutton" data-inc="-1">-</div>
  <form method="POST">
    <input class="cart-plus-minus-box" data-productid="5" type="integer" value="2" disabled>
  </form>
  <div class="inc qtybutton" data-inc="1">+</div>
</div>

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!