Reputation: 65
Is there any jquery event which is called when the readonly value of the text box is changed automatically
I want to call an event (jquery) which should be called when the readonly value of the textbox is changed some how by other jquery events.
Early Reply is highly appreciated.
Best Regards, Sagar
Upvotes: 2
Views: 5494
Reputation: 186
Just like Sagar Dixit said in his answer, you can trigger the change event manually.
// trigger the change event as soon as you set new value to the readonly field
$('input').val(newValue).trigger('change')
...
...
// Listen to the change event
$('input').change(function() {
// Handle the change
})
Upvotes: 0
Reputation: 1
Well as of my knowledge and research is saying that you have to do this way : http://jsfiddle.net/kmvSV/1/
$(document).ready(function () {
$('input[id$=_txtTest]').bind("change", function () {
alert($(this).val());
});
$('button').bind("click", function () {
$('input[id$=_txtTest]').val('hello').trigger('change');
});
});
Upvotes: 0
Reputation: 25685
You could add a change event to your <input>
and test for the readonly attribute:
$('input').change(function(){
if($(this).attr('readonly') == true){
// do something fancy
}
});
Upvotes: 1
Reputation: 13438
You could add a function that will be executed every N
seconds (via setInterval
) and check for the field value. It is very ugly, though.
Upvotes: 0
Reputation: 3981
would the change() method not work?
$('input:readonly').change(function() {
alert("Readonly input changed!!");
})
Upvotes: 0
Reputation: 630607
There is no event for this (not one you would want to attach to, a general DOM change event handler would have horrible performance).
If you expanded on the context a bit, there may be another solution to get what you're after, for example what's setting it to readonly?
Upvotes: 2