showing results for - "selectpicker set value jquery"
Neele
01 Jan 2019
1The value is correctly selected, but you didn't see it because the plugin hide the real select and show a button with an unordered list, so, if you want that the user see the selected value on the select you can do something like this:
2
3//Get the text using the value of select
4var text = $("select[name=selValue] option[value='1']").text();
5//We need to show the text inside the span that the plugin show
6$('.bootstrap-select .filter-option').text(text);
7//Check the selected attribute for the real select
8$('select[name=selValue]').val(1);
9Edit:
10Like @blushrt points out, a better solution is:
11
12$('select[name=selValue]').val(1);
13$('.selectpicker').selectpicker('refresh')
14Edit 2:
15To select multiple values, pass the values as an array.