Leo Leo - 5 months ago 14
Javascript Question

How to trigger change event for Chosen (jQuery)

Before I click reset button I choose "Company" in Chosen (dropdown list). The event occurs normally after I click reset. I choose "Company" again but event

change
in dropdownlist doesn't occur.

Could anyone tell me how to trigger the change event for dropdownlist after clicking reset button and then the same element?

The code I have so far:

$("#mainMenu").change(function(e){
e.preventDefault();
loadFirstManu(true);
});


Code for the reset button:

$("#btn_reset").click(function() {
CKEDITOR.instances.ckeditor.setData('');
$('.mchosen').each(function() {
$(this).val('').trigger('liszt:updated');
$('#submenu').attr('disabled', 'disabled').html('');
$('#secondsubmenu').attr('disabled', 'disabled').html('');
$('#s-menu').removeClass('required').html('');
$('#secondsubmenu').removeClass('validate[required]');
$('#tabmenu').attr('disabled', 'disabled').html('');
$('#tab').removeClass('required').html('');
});


});

Answer

This is what i figured out:

$('#my-select').val(5).trigger("liszt:updated")

liszt:updated is no longer working in new version of chosen instead use below as Alexandru Cojan's answer suggesting

 trigger("chosen:updated");