7

I'm working with jquery.

And i have text input in a form, i would like to process the change event.

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

the event is fired normally when i edit the field manually, but when i change the field's value with a script (sometimes with an external script) it doesn't work.

is there any solution ?

and thanks in advance.

1

4 Answers 4

12

The change event is not designed to detect programmatic changes. You can trigger the event manually when setting the value, though:

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

shortcut:

$('#my_input').change();
Sign up to request clarification or add additional context in comments.

3 Comments

is there an event that fires when the input is changed programmatically ?
@Youcef04: No, JavaScript does not support that kind of monitoring. Some other languages have constructs that allow stuff like this, but not in JavaScript.
@Youcef04: It would be nice if you could accept this answer if I was able to help you :)
0

Fire them manually, using one of the following two functions:

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

Comments

0

You can use live/delegate to bind your change event

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

Comments

0

here is the code

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.