Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fire onchange event for TextBox when readonly is true

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?

like image 505
Ashwani K Avatar asked Jan 15 '13 07:01

Ashwani K


1 Answers

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');
   });
 });
like image 177
Jai Avatar answered Sep 22 '22 06:09

Jai