Click here to Skip to main content
Licence 
First Posted 5 Dec 2002
Views 28,577
Bookmarked 8 times

HTML Forms -- Accidental Abort Alerting

By | 5 Dec 2002 | Article
Here we present an elegant way that when the user fills half of the HTML form contents and tries to navigate to a different page, he does not lose anything that is partially filled.

Introduction

We normally use long forms in our web pages that collect various types of information from the users/visitors. Since HTTP is a stateless protocol, there is no way for the server to know whether the user has completed filling up the form (unless he submits it) or just clicked any of the links (after filling half of the form) that takes him away from the form, thus discarding whatever he has typed till that point.

The Solution

With some small event handler facilities allowed for forms in Microsoft Internet Explorer and with the help of JavaScript, it would be easier to detect whether the browser is about to navigate away from the page containing the form, when there are contents filled by the user but yet pending to be submitted/postedback to the server.

Benefits

The user might have got interested on some links while he is half-way filling up the form and might have clicked it accidentally. If our form could alert him that this action of his could cause loss of whatever information that he has made in the HTML form, it would really be helpful to the user, particularly when the form contains large TextArea contents and user has typed significant amount of text in it.

This also relieves the server/developer to keep track of all links as LinkButtons or PostBack so that even if user clicks any of the links, whatever the user submits keep bouncing back and forth between the server and client till user decides to go forward submitting it or discard whatever he has typed into the form.

I hope that this small piece of JavaScript code would really be helpful in making HTML Forms really more friendly to the user.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Vasudevan Deepak Kumar

Web Developer

India India

Member

Vasudevan Deepak Kumar is from Chennai, India who has been in the programming career since 1994, when he was 15 years old. He has his Bachelors of Engineering (in Computer Science and Engineering) from Vellore Engineering College (now VIT University). He also has a MBA in Systems from Alagappa University, Karaikudi, India.


He started his programming career with GWBasic and then in his college was involved in developing programs in Fortran, Cobol, C++. He has been developing in Microsoft technologies like ASP, SQLServer 2000. For sometime, he has also been with PHP and MySQL based development in one of his previous organizations. Now currently his focus is on Microsoft .NET World (ASP.NET, C# and Whidbey)


In his past-time, he listens to polite Carnatic Music.

Web Presence


Homepage

http://www.lavanyadeepak.tk/

Blogs



Technical




Gossips



Spiritual







Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 6 Dec 2002
Article Copyright 2002 by Vasudevan Deepak Kumar
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid