Dynamically Changing Button Names on Click

When click On button Changing Button Names

In HTML Part :-

 @foreach($filteredData as $item)
<form class="add_to_cart_form" data-item-id="{{ $item->id }}" id="add_to_cart_form" enctype="multipart/form-data" role="form">
                @csrf
                <div class="social">
                    <!-- <span class="border border-success"> -->
                    <div class="buttons" id="my_checkbox">
                        @if (!empty($item->face_price))
                        <input type="checkbox" class="btn" name="face_price" id="" value="{{ $item->face_price }}">
                        &nbsp;<a href="{{$item->facebook}}" target="_blank"> Facebook:</a>
                        &nbsp;${{ $item->face_price }}/post</span><br><br>
                        @else
                        <input type="hidden" value="" name="">
                        @endif
      
                        @else
                        <button type="submit" id="sample_form_pic{{ $item->id }}" class="btn btn-sm py-1 btn-primary me-2">Add To Cart</button>
                        @endif




                    </div>
                   


                </div>
            </form>
@endforeach

In javascript :-

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
  $(document).ready(function() {
    $('.add_to_cart_form').submit(function(e) {
        e.preventDefault(); // Prevent form submission
        if ($(this).find(':checkbox:checked').length === 0) {
            alert('Please click on a checkbox.'); // Display warning message
            return;
        }
        // Get the button ID based on the form's data-item-id attribute
        var itemId = $(this).data('item-id');
        var buttonId = '#sample_form_pic' + itemId;

        // Serialize the form data
        var formData = $(this).serialize();

        // Send the Ajax request
        $.ajax({
            url: 'add_summary', // Replace with the actual route URL
            type: 'POST',
            data: formData,
            success: function(response) {
                // Handle the success response here

                // For example, you can update the UI to show that the item is added
                $(buttonId).text('Added').attr('disabled', true);
            },
            error: function(xhr) {
                // Handle the error response here
            }
        });
    });
});



</script>

Output:-

Related Posts

Explore deeper with Certified MLOps Manager monitoring and automation basics

Introduction The gap between developing a machine learning model and deploying it into a reliable production environment is where most artificial intelligence projects fail. The Certified MLOps…

Read More

Certified MLOps Architect: Skills, Syllabus, and Career Opportunities Explained Clearly

Introduction The Certified MLOps Architect is a comprehensive program designed for professionals who want to bridge the gap between machine learning and production engineering. This guide is…

Read More

Advanced Certified MLOps Professional Program for Scalable AI Model Deployment Systems

Introduction The Certified MLOps Professional program from AIOpsSchool has emerged as a vital benchmark for engineers looking to bridge the gap between data science and production engineering….

Read More

Powerful Certified MLOps Engineer Program to Build Reliable ML Infrastructure

Introduction The integration of Machine Learning into production environments has created a significant gap between data science and traditional software engineering. The Certified MLOps Engineer program is…

Read More

Professional Skill Alignment Around MLOps Foundation Certification in Modern Workplaces

Introduction The MLOps Foundation Certification has emerged as a critical benchmark for professionals looking to bridge the gap between data science and production engineering. This guide is…

Read More

Certified AIOps Manager: Strategic Framework for Intelligent IT Operations

Introduction The Certified AIOps Manager program is a specialized training designed to help professionals lead the next wave of IT operations. This guide is for engineers and…

Read More