Home > other >  Select Dropdown items based on selection from another dropdown (Multiselect dropdown)
Select Dropdown items based on selection from another dropdown (Multiselect dropdown)

Time:04-05

I have 2 multi select drop downs: #ListData and #ListChart.

Both of these have identical items in them. What I like do do is when I select #ListData, I like to have #ListChart have the identical items selected.

I have the following but not working in that #ListChart does not update to have the same items as #ListData.

 $('#ListData').change(function(){

   var selectedItems = $('#ListData').val();
   $("#ListChart").val(selectedItems);
   $("#ListChart").multiselect("refresh");

 }

Below is what the array looks like:

enter image description here

CodePudding user response:

I'm presuming it's because you haven't triggered the change?

Use .trigger() such as below:

$("#ListChart").val(selectedItems).trigger('change');

Alternatively you could just use change()

$("#ListChart").val(selectedItems).change()

[![enter image description here][1]][1]

See here for more information

CodePudding user response:

I figure that the value is modify but the displaying component is not correctly update, try this :

$("#select1").on("change",function() {
  $("#select2").val($(this).val())   
  $(".filter-option-inner-inner").html( $(this).val().length > 0 ? $(this).val().join(', ') : "Nothing selected")
})
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.18/css/bootstrap-select.min.css" integrity="sha512-ARJR74swou2y0Q2V9k0GbzQ/5vJ2RBSoCWokg4zkfM29Fb3vZEQyv0iWBMW/yvKgyHSR/7D64pFMmU8nYmbRkg==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.18/js/bootstrap-select.min.js" integrity="sha512-yDlE7vpGDP7o2eftkCiPZ yuUyEcaBwoJoIhdXv71KZWugFqEphIS3PU60lEkFaz8RxaVsMpSvQxMBaKVwA5xg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

<div>
  <select  id="select1" multiple>
    <option>Mustard</option>
    <option>Ketchup</option>
    <option>Relish</option>
  </select>
</div>
<hr/>
<div>
  <select  id="select2" multiple>
    <option>Mustard</option>
    <option>Ketchup</option>
    <option>Relish</option>
  </select>
</div>

  • Related