Trigger the change event of a textbox in jQuery

Posted by Danny Chen on Stack Overflow See other posts from Stack Overflow or by Danny Chen
Published on 2010-05-17T10:19:07Z Indexed on 2010/05/17 10:20 UTC
Read the original article Hit count: 229

Filed under:
|
|

I have an asp:TextBox with asp:RegularExpressionValidator to validate if it's a number. Obviously an onchange event will be attached to this textbox while rendering. Also I add a change event at $(document).ready to make some calculation when the value is changed.

<asp:TextBox id="myText" runat="server" />
<asp:regularexpressionvalidator id="myRev" ControlToValidate="myText" runat="server">*</asp:regularexpressionvalidator>

$(document).ready(function(){
    $('[id$=myText]').bind('change',function(){
           //do something
    }).change();      //force the change event at the very beginning
});

My function will be executed later than the .net generated js because of the register time. But the .net js throws an error. I traced in the js:

   function ValidatorOnChange(event) {
       ...
   }

and found that all of event.fromElement,event.toElement,event.srcElement are null which causes the exception. Did I do something wrong? Any solutions? Thanks.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about ASP.NET