Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to trigger change event for Chosen (jQuery)

Tags:

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('');   }); 

});

like image 266
Leo Avatar asked Feb 27 '13 01:02

Leo


People also ask

How do I create a trigger drop change event?

$(document). ready(function(){ $('#countrylist'). change(function(e){ // Your event handler }); // And now fire change event when the DOM is ready $('#countrylist'). trigger('change'); });

What is trigger change in jQuery?

The trigger() method is a method in jQuery which is used to trigger a specified event handler on selected element. Syntax: $(selector).trigger(event, param1, param2) Note: Extra parameters can be passed in trigger() method. Example 1: This method triggered two methods to increase the value of method.


2 Answers

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"); 
like image 105
bonyiii Avatar answered Sep 24 '22 18:09

bonyiii


for newer version of chosen the event is "chosen:updated"

$(selector).trigger("chosen:updated") 
like image 42
Alexandru Cojan Avatar answered Sep 22 '22 18:09

Alexandru Cojan