Search code examples
javascriptjquerycheckboxdropdownlaravel-9

Update Multiple Dropdowns(5drop) values with the same name in jQuery and values comes dynamically from json


firs image, dropdown with loop, here are 3 dropdwonsValues that i want to update or load those drop downs

1st dropdown values(1, 2, 3, 4, 5) second dropdown values(25, 26, 27, 28, 29) third dropdown values(35, 36, 37, 38, 39)

I want every drop down to be loaded with that data and it is  dropdown, the data needs to be loaded dynamically or automatically to get the update.
$('select[name="SubCategoryID[]"] option').each(function (e, v) {
  if (val.SubCategoryID == v.value) {
    console.log('', v.value); 
    $(`select[name="SubCategoryID[]"] option value`).find(v.value).val(v.value) 
  } else { 
  }
});

Solution

  • i got the solution, the code is below

           $('select[name="SubCategoryID[]"] option').each(function (e, v) {
    
                            if (val.SubCategoryID == v.value) {
                                console.log('dropdown', $(this).val());
                                $(this).attr("selected", "selected");
                                $(`select[name="SubCategoryID[]"] option value`).find(v.value).val(v.value)
                            } else {
                                // console.log('Done');
                            }
                        });