Link to home
Start Free TrialLog in
Avatar of MitchellVII
MitchellVIIFlag for United States of America

asked on

Want to automatically save webform contenst anytime the user leaves the form...

Hi, I have a webform that consists of multiple pages.  I am running some .asp script to save the data to a MySQL Database when the user clicks a button on the bottom of the form.

However, I would like to trigger the form action so that the changes made are saved anytime the user navigates away from the page just in case they accidentally go to another page without clicking the button and lose all their data.

How do I do that?
Avatar of Gurvinder Pal Singh
Gurvinder Pal Singh
Flag of India image

you can invoke the same method (you are invoking on button click event) on
onbeforeunload event of body tag

See the following page for reference
http://msdn.microsoft.com/en-us/library/ms536907(VS.85).aspx
http://reference.sitepoint.com/html/extended-event-attributes/onbeforeunload#
Avatar of MitchellVII

ASKER

Thanks.

Ok, my current <form> looks like this:

<form method="post" id="DocEPW_IT_Demographic" action="scripts/asp/DocEPW_INSERT_IT_Demographic.asp" enctype="multipart/form-data">

and my button looks like this:

<input name="Submit" type="submit" class="button" value="Save and Continue!" tabindex=-1>

What exactly would I add to my body tag to make it run my .asp script on the "onbeforeunload" event?


That dialog box would drive me nuts, I could imagine what your visitors would do/think
If they had to put up with that box and its annoying noise, especially if you have a person
On your Form, that has his music turned up loud, that Dialog noise can take out your speakers.

You can do this using AJAX in what is called inline editing.
Once the user types in the information into a field it is automatically stored into the database.
I have been trying to work out the kinks in a demo code that I found, but have not had much luck at it yet.

You can view the demo here and if you have any luck or idea's in getting it to work properly
Please let me know.

http:Q_24976285.html ( InLine Editing using AJAX)

Carrzkiss
"That dialog box would drive me nuts, I could imagine what your visitors would do/think
If they had to put up with that box and its annoying noise, especially if you have a person
On your Form, that has his music turned up loud, that Dialog noise can take out your speakers."

Sorry, but what are you talking about?

My website doesn't have any dialog boxes that play music.  Also, I don't think I provided a link to my website in my post.
I take it you have not gone to the website provided be Mitchell?
http://msdn.microsoft.com/en-us/library/ms536907(VS.85).aspx

Check out the demo.
And it does not play music, you totally misread what what I wrote.

The link to the microsoft deal checks to see if you close the page, and if you do
It gives you a warning to let you know that you are trying to navigate away from the
Page, it is these types of things that most spam popup windows have.

Anyway, check out the link and you will see what I am referring too.

Carrzkiss
Ah ok, you were referring to the link provided by the other expert and not my website.  Ok, sorry.
@MitchellVII: Did you tried the solution i suggested? Is it working fine for your requirements?

Thanks
qurv,

Thanks for asking.

I checked it but it is not working.  I am using the following:

<body lang=EN-US onLoad="elmLoop();disableAutoComplete('DocEPW_IT_Group')" onbeforeunload="document.forms[0].submit();">

<form method="post" id="DocEPW_IT_Group" action="scripts/asp/DocEPW_INSERT_IT_Group.asp" enctype="multipart/form-data">

But when the user navigates away from the page, the action is not firing as changes made are not being saved.
"But when the user navigates away from the page, the action is not firing as changes made are not being saved."

Are you saying that
onbeforeunload="document.forms[0].submit();"
is not submitting the form?



correct, it is not.
ASKER CERTIFIED SOLUTION
Avatar of Gurvinder Pal Singh
Gurvinder Pal Singh
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ok, I'll try that.  Gimme a day or so.