Laravel Ajax if first and second select equal to

Posted 4 months ago by pickab00

So I have two select tags with options. Now so far I have a return value from my select tag if it is equal to a specific value. To put it in to perspective here is my ajax

function checkFreeMeal() {


    var url_origin   = window.location.origin;

    $('#existing_guest_selector').on('change', function() {

        var guestID = this.value;

        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });
        $.ajax({
            type: "GET",
            url: url_origin + '/restaurant-reservations/check-free-meal/' + guestID,

            statusCode: {
                500: function() {
                    $('.something-went-wrong').text('err');
                }
            },
            success: function(data) {
                if (data == 1){
                    $('.free-meal').prop('checked', true);
                }if(data == 0){
                    $('.free-meal').prop('checked', false);
                }
            }
        });

    });

}

My guest ID is coming from my select option value and it is sending to URL which expects a parameter which is the guest ID.

Now I have another Select field which I would Like to use to check if the result is 1 or 0. I want to first check if the guest id returns 1. And later check if the meal plan id returns 1. If they both return 1 from a controller, do something. Currently as mentioned on the code above, My route/URL expects one param and one select change. How can I check two select change and pass those two ID's (guest ID and meal plan ID) to the route? I can write the controller from there. I just want to know How I can pass two select values in to one ajax/route. So guest on change and meal plan on change, pass two id's to the url (something like restaurant-reservations/check-free-meal/' + guestID + '/' + mealPlanID).

Please sign in or create an account to participate in this conversation.