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);

DEMO

Using BOOTSTRAP SELECT,

jQuery("#app_id option").filter(function(){
    return $.trim($(this).text()) ==  'Application 2'
}).prop('selected', true);
$('#app_id').selectpicker('refresh');

DEMO

Share:
19,499
jagamot
Author by

jagamot

Software Professional

Updated on June 07, 2022

Comments

  • jagamot
    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>