javascript - How to select multiple select based on values? -


this question has answer here:

i have html

<select name="availableon[]" class="form-control" multiple>      <option value="pc">pc</option>      <option value="iphone">iphone</option>      <option value="android">android</option>  </select> 

and in ajax success function have value

availableon = 'pc,iphone' 

now want explode availableon variable , select multiple select based on value using javascript or jquery. how that?

you can change data array , set value array

var availableon = 'pc,iphone'    var dataarray = availableon.split(",");    $("select").val(dataarray);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <select name="availableon[]" class="form-control" multiple>       <option value="pc">pc</option>       <option value="iphone">iphone</option>       <option value="android">android</option>   </select>


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -