I am attempting to capture when a text input field's value is changed. I am using:
$("input[name=color]").change(function(){
This works if I type the new value in directly. However, the value of the input field is being changed by jquery. There are several of these fields, and I need to know when any have changed. Is there a way to detect this change?
Sorry, I wasn't clear. I'm not the one changing the value. It's an addon that I would rather not modify in case I need to port it to another project.
WORK-AROUND
Ok, so you can't do what I wanted to do, but here is a work-around. I just made an interval and changed my change
event to an each
event.
setInterval(function(){
$("input[name=color]").each(function(){ my code })
},100);
There is no way to detect the changes done programmatically.
However you can trigger a change
event whenever you modify its value.
$("input[name=color]").val("newValue").change();
When change the value by jquery you can fire the change event with jquery afterwards
$("input[name=color]").val('someValue').trigger('change');
No, onchange event will not be triggered when the value is changed using javascript. Alternatively you can call the onchange event when you change the value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With