javascriptjquerybootstrap-select

How to select dynamically in Bootstrap-select with multiple values


How can I select dynamically in Bootstrap-select with multiple values, if my values are 1,3,4, using jQuery?

Here is my select:

 <select  id="myselect" name="myselect[]" multiple>
        <option value=""></option>
        <option value="1">red</option>
        <option value="2">orange</option>
        <option value="3">green</option>
        <option value="4">blue</option>
</select>


Solution

  • Use Bootstrap-Select's val method:

    $('#myselect').selectpicker('val', [1,3,4]);
    

    http://jsfiddle.net/a4bxnwws/

    See Bootstrap-Select's documentation.