We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

jquery causing extra TextChanged events

AlliedAdmin
AlliedAdmin asked
on
Medium Priority
1,060 Views
Last Modified: 2012-05-11
I have a form that has 3 text boxes that are masked using the jquery input mask plugin.  All 3 textboxes have a TextChanged event and AutoPostBack=true;
The problem is that when I change the text of one textbox and hit enter, it is firing the TextChanged event for all 3 boxes.

I assume that it is due to how jquery does the masking, and that it changes the text at a point late enough in the event cycle that .net registers it as being changed.  Is there a way to prevent it?  I have tried using return false at the end of my jquery function, but it's not helping either.

Here is the relevant jquery code, at the top of my aspx page:

 jQuery(function(){
            $("#<%= txtPrimaryPhone.ClientID %>").mask("999-999-9999? x9999");
            $("#<%= txtOtherPhone.ClientID %>").mask("999-999-9999? x9999");
            $("#<%= txtZip.ClientID %>").mask("99999?-9999");
            return false;
        });

Open in new window


Thanks
Comment
Watch Question

You perform the masking for all the 3 text boxes in single function and calling that function if first text box is it?

Author

Commented:
I'm not really sure what you mean, but that function will mask all 3 of my inputs, which are 2 phone numbers and a zip code.

Each of those text boxes has an OnTextChanged event (server side event) that is fired when the text is changed.  However, the OnTextChanged event is firing for all 3, even if I only change one text box.  For example, if the page loads up, and I change the zip code from 12345 to 54321 and hit enter, it is firing the OnTextChanged event for all 3 inputs, even though only one actually changed.
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.