Onchange input event not firing on jquery

I am working with jquery.

And I have text input on the form, I would like to handle the change event.

$("#my_input").change(function(){alert('123');}); 

The event fires normally when I edit the field manually, but when I change the value of the field using a script (sometimes with an external script), it does not work.

is there any solution?

and thanks in advance.

+7
source share
4 answers

The change event is not intended to detect software changes. You can trigger the event manually when setting the value:

 $('#my_input').trigger('change'); 

Label:

 $('#my_input').change(); 
+11
source

Fire them manually using one of the following two functions:

 $('#my_input').trigger('change'); $('#my_input').change(); 
0
source

You can use live / delegate to bind change event

 $("#my_input").live('change',function(){alert('123');}); 
0
source

here is the code

 $("input[type='text']").change( function() { // check input ($(this).val()) for validity here }); 
0
source

All Articles