How to reset value of Bootstrap-select after button click

61,465

Solution 1

Without "option:selected"

$("#dataPicker").val('default');
$("#dataPicker").selectpicker("refresh");

Solution 2

You can write it in one single line reduces extra piece of code.

$("#dataPicker").val('default').selectpicker("refresh");

Solution 3

you can easily solve this problem by adding the autocomplete attribute to the select-element and set it to "off".

<select id="dataPicker" class="selectpicker form-control" autocomplete="off">
  <option value="default" selected="selected">Default</option>
  <option value="one">One</option>
  <option value="two">Two</option>
  <option value="three">Three</option>
</select>
Share:
61,465
Admin
Author by

Admin

Updated on September 10, 2020

Comments

  • Admin
    Admin over 3 years

    I am using Bootstrap-select plugin (https://silviomoreto.github.io/bootstrap-select/) for my dropdown select box. After I click a button, I want the box to refresh and the "selected" option to reset. This is the dropdown

    <select id="dataPicker" class="selectpicker form-control">
      <option value="default" selected="selected">Default</option>
      <option value="one">One</option>
      <option value="two">Two</option>
      <option value="three">Three</option>
    </select>
    

    And this is my attempt at it, does not work. Any ideas on how it should be?

    $("#dataPicker option:selected").val('default');
    $("#dataPicker").selectpicker("refresh");
    
  • Apps-n-Add-Ons
    Apps-n-Add-Ons about 6 years
    $('.selectpicker').selectpicker('refresh'); works to reset the picker(s) on the page (I have several and this was the best choice).