1

I am using skote theme and I want to set auto select value in multiple select select box when edit data I have get this multiple select box from this this for that I am trying below code

    <select class="select2 form-control select2-multiple" name="assign_to[]" multiple="multiple"                                     data-placeholder="Choose ...">
    <option value="1" data-select2-id="1">Admin</option>
    <option value="2" data-select2-id="2">Admin2</option>
    <option value="3" data-select2-id="3">Admin3</option>
</select>


    $(document).on('click','.edittodotask',function(e){

    e.preventDefault();
    var id = $(this).attr('id').replace('edittodotask_', '');
    var url = "{{route('task_to_do.edit', ':id')}}";            
    url = url.replace(":id", id);

    
    $.ajax({
        type: "get",
        url: url,
        processData: false,
        contentType: false,
        success: function(response) {
            //response = assign_to: "1, 2"                
            var assign_to = response.assign_to.split(',');                
            $("#edit_assign_to").val(assign_to);            
        },
        error: function(data) {
            console.log(data);


        }
    })
    
});

when I click on edit button I have get data with ajax and want to set auto select options for that I have make this code

but it is not set selected value.

can anybody help me with this

Alexandre Elshobokshy
  • 10,720
  • 6
  • 27
  • 57
Mohini
  • 268
  • 3
  • 15
  • @IslamElshobokshy please check it now – Mohini Aug 17 '20 at 08:51