Preventing Form Resetting

In an application I am creating, I do validation, filtering and ajax saving of values when the user changes something in a textbox.

A problem arrises if the user makes some changes, and then presses the Esc key 2 times.  This causes the form to reset, but it skips all my validation and auto-saving logic.

To prevent this, you can use this little snippet of jQuery javascript:

$(document).ready(
     function() {
         // prevent the esc key from resetting all the textboxes
          $("form").bind("reset", function(e) {
             e.preventDefault();
         });
     }
 );

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s