I am trying to have some functionality on change of a textbox which is readonly. But when I am trying to update the textbox using javascript, the change event is not firing for the textbox.
<script type="text/javascript">
$(document).ready(function () {
$('input[id$=_txtTest]').bind("change", function () {
alert("test");
});
});
function ChangeText() {
$('input[id$=_txtTest]').val('hello');
}
</script>
I am calling ChangeText method on click of a button. But it is not firing the textchange event for the textbox.
Can anybody tell me what is wrong here?
Well 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');
});
});
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