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

239
Views
how can I change the text of the button

I need to change the text of the button after the success adding to the basket. But it change it just after the second click. How can I change it if Im using foreach in php

<td>
<?if(count($arElement["OFFERS"]) > 0):?>
    <?foreach ($arElement["OFFERS"] as $offer): ?>
        <?//var_dump($offer["ID"]);?>
        <div class="button456" >
            <button class="button-offer" id="but123" onclick="add2basket(<?=$offer["ID"]?>)">To the basket</button>
    <?endforeach?>

<?else:>
    <button class="button-simple" id="but1234" data-id="12345" onclick="add2basket(<?=$arElement["ID"]?>)">To the basket</button>
<?endif?>
        </div>
</td>
<script type="text/javascript">
function add2basket(ID) {
    $.ajax({
        type: "POST",
        url: "/ajax/add_tobasket.php",
        dataType: 'html',
        data: {PRODUCT_ID: ID,QUANTITY: $(".quantity" + ID).val(),},
        success: function (html) {
            $('button').on('click', function(){
                $(this).closest('button').text("In the basket");
            });
        },
    });
}
about 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!