Skip to main content

Posts

Showing posts with the label jQuery

Using jQuery to handle confirmation of navigating away from HTML Forms in edit mode

On my recent project, I had a requirement that stated that I needed to warn the end users when they tried to navigate away from an HTML Form that they started editing. The warning message was to indicate that they were leaving and they forgot to hit the submit button. There are many ways for end users to navigate away from a given HTML Form. They could click a link within the application, they could close the browser, or type in a new URL. This solution focuses on clicking available links on the application they are on. For this solution I used jQuery. I am a big fan of jQuery and I use it whenever I can. The solution basically involves tracking user activity when they are working with an HTML Form. By tracking I mean to capture their actions when they click/focus on HTML form elements such as input, select, textarea, radio, and checkbox. Here is the code that handles all this: var somethingChanged = false; $(document).ready(function() { handleReady(); }); function handleReady() { ...