I have tried numerous things and nothing seems to be working.
I am using jQuery and Chosen plugin.
Methods I have tried:
var select = jQuery(
Exactly i had the same requirement. But resetting the drop down list by setting simply empty string with jquery won't work. You should also trigger update.
Html:
<select class='chosen-control'>
<option>1<option>
<option>2<option>
<option>3<option>
</select>
Jquery:
$('.chosen-control').val('').trigger('liszt:updated');
sometimes based on the version of chosen control you are using, you may need to use below syntax.
$('.chosen-control').val('').trigger("chosen:updated");
Reference: How to reset Jquery chosen select option
Try this to reload updated Select box with Latest Chosen JS.
$("#form_field").trigger("chosen:updated");
http://harvesthq.github.io/chosen/
It will Updated chosen drop-down with new loaded select box with Ajax.
jQuery("#autoship_option option:first").attr('selected', true);
$('#autoship_option').val('').trigger('liszt:updated');
and set the default option value to ''
.
It has to be used with chosen updated jQuery available at this link: https://raw.github.com/harvesthq/chosen/master/chosen/chosen.jquery.min.js.
I spent one full day to find out at the end that jquery.min
is different from chosen.jquery.min
If you are using chosen
, a jquery plugin, then to refresh or clear the content of the dropdown use:
$('#dropdown_id').empty().append($('< option>'))
dropdown_id.chosen().trigger("chosen:updated")
chosen:updated
event will re-build
itself based on the updated content.
The first option should sufice: http://jsfiddle.net/sFCg3/
jQuery('#autoship_option').val('');
But you have to make sure you are runing this on an event like click
of a button or ready
or document, like on the jsfiddle.
Also make sure that theres always a value attribute on the option tags. If not, some browsers always return empty on val()
.
Edit:
Now that you have clarifyed the use of the Chosen plugin, you have to call
$("#autoship_option").trigger("liszt:updated");
after changing the value for it to update the intereface.
http://harvesthq.github.com/chosen/