I have list of input fields. In which some are readonly fields. I am using .keyup() event to trigger when something changes in input field. But it won't effect for readonly field. Somehow i want to change those fields also . Any help?
If you call focus
on a readonly input field, then keyup
events will fire. However, typing in that field won't change its value (afterall, it's read-only). Perhaps what you need is to listen for changes in its value
attribute instead?
I'd suggest listening to input
and propertyChange
as this answer suggested:
$('input').bind('input propertychange', function() {
// Do something
});
This way when your input value changes (from any means) you'll be notified. Edit: does not work if you programatically change the value - for this case, the only cross-browser viable alternative involves polling (for instance this). A better option could be using a framework such as knockout.js, that automates this for you while providing clear separation between view and model. Here's an example.
Update: I recall reading your comment in a deleted answer, stating that you're programatically setting the value of the input, is that correct? (could some user with 10k rep please restore it?) In that case, why not have the code that is changing the value trigger the listener directly?
$(link).click(function() {
$(readonlyInput)
.val("some val") // Update the value
.trigger('keyup'); // Trigger the listener
});
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