Bootstrap Select - Set selected value by text
19,499
You can use jquery filter() and prop() like below
jQuery("#app_id option").filter(function(){
return $.trim($(this).text()) == 'Application 2'
}).prop('selected', true);
Using BOOTSTRAP SELECT,
jQuery("#app_id option").filter(function(){
return $.trim($(this).text()) == 'Application 2'
}).prop('selected', true);
$('#app_id').selectpicker('refresh');
Comments
-
jagamot almost 2 years
How can I change the drop down if I only know the text and not the value?
Here is my select -
<select id="app_id" class="selectpicker"> <option value="">--Select--</option> <option value="1">Application 1</option> <option value="2">Application 2</option> </select>