Bootstrap Select - Set selected value by text -


how can change drop down if know text , not value?

here select -

 <select id="app_id" class="selectpicker">        <option value="">--select--</option>        <option value="1">application 1</option>        <option value="2">application 2</option>  </select> 

you can use jquery filter() , prop() 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


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -