javascript – Reset value of a select field with jQuery/Boostrap

Question:

Hi, how can I reset a select field?

<label for="IDSelect">Campo</label>
<select data-live-search="true" title="--" name="NAMESelect" id="IDSelect">
    <option value="1">Valor 1</option>
    <option value="2">Valor 2</option>
</select>

Note that the default value when loading the page is "–", I want that after selecting an option and submitting this form (submit with jquery), go back to the default value "–"

Answer:

To reset the boostrap select you have to do:

$('select').val('').selectpicker('refresh');

jsfiddle: https://jsfiddle.net/t0u1j6L8/2/

With .val('') say that the value should be cleared and with .selectpicker('refresh') you make it refresh 🙂

( you could also use it like this , with .trigger('change') )

Scroll to Top