sarky
1 week ago
105
6
General

Ajax to pass onchange

Posted 1 week ago by sarky

Good day guys

Trying to pass data and update the database on.change of a Select option

At the moment It is passing the information but only working on the first Select Option and not the second or 3rd.....

Can someone have a look and tell me what I am doing wrong or omitted ?

Cheers in advance

<form method="POST" id="changeorder">
                            @csrf

                        <select name="orderid" id="orderid" class="custom-select" data-live-search="true">
                            <option selected>Open this select menu</option>
                        @foreach($orders as $order)
                            <option value="{{$order->id}}|{{$deliver->id}}" {{ $order->id == $deliver->order_id ? 'selected' : '' }}>{{$order->customer->name}}
                                ---{{$order->jobno}}</option>
                        @endforeach
                        </select>
                        </form>

Below is the script I am using

<script>
    $(document).on('change','select',function(){
        let changeorder =  $('#changeorder').serialize();
        $.ajax({
            url: '/delivery/changeorder',
            data: changeorder,
            type: 'POST',
            success: function(response) {
                console.log(response);
            }
        });
    })
</script>

Thanks again Sarkis

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