Link to home
Start Free TrialLog in
Avatar of lshane
lshane

asked on

How to refresh a page and not clear form contents

Hi. I am using ASP VBScript (not .NET).

I have created a form on a page.  When data is entered, I would like for it to remain after refreshing the page.  I will clear it with the "Clear" button, but I don't want it to clear until then.

I'm not sure if this has something to do with "Session Variables", or not.

Could someone, please, assist me with this?

Thanks so much.
Avatar of HuyBD
HuyBD
Flag of Viet Nam image

Hi lshane!
add script to your file

<script>
window.onload = function () // when the window is reloaded, check if a scroll value has been saved
   {
return;
   }
</script>
Avatar of Cirieno
Cirieno

Depending on what you mean by "refresh" (I'm assuming you don't mean "submit", because then all you'd have to do is prent out the received values) there is one solution that I can see, with two methods: use javascript to save the values as they are typed.

The time increment is up to you but I'd suggest saving values after 5 seconds of keyboard inactivity.  Now as to where you save the values, you could save them either to a cookie (if they are small values, remembering a cookie has limited size and not everyone has them turned on) or to a server (using a sessionid as the person's identity).

This idea is taken from one of the fundamentals of the Javascript tecjnology named Ajax, so either look around EE for more help on that or browse the hundres of tutorials on the web.  Basically you're saving what people type as they type, so when the page is refreshed you can pull back the information as it was stored only 5 (or whatever) seconds ago.

Of course, if the user doesn't have Javascript turned on this technique won't work and I can't think of a non-scripted solution...
Avatar of lshane

ASKER

Good points.  I am actually referring to when someone presses the "refresh" button on the browser.  That always clears the form.  Perhaps it should.  I was mainly wanting to know if there was a way to keep it from clearing when the "refresh" button is pressed, and to only clear when a user presses the "Clear" button on the form.

Is that possible, or even useful?
ASKER CERTIFIED SOLUTION
Avatar of Cirieno
Cirieno

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
Avatar of lshane

ASKER

Great. I suppose that is what I was needing to know... that the "Refresh" button is meant to operate that way.  It seems that what I was trying to do may not even be useful unless the user has a LOGIN.

Thanks so much.
No problems, thank you :)

As an aside: to use the options I've listed above, the user wouldn't have to be logged in as they would be given a session ID when they open their first page -- if you keep that session ID with them all long the way (either as a querystring value, and/or hidden inside forms) then it doesn't matter if they are logged in or not, you can still track them and so still save the data as attached to that sessionID.  Just a thought.

Avatar of lshane

ASKER

Great.  Thanks for the addendum.  I still have some things to learn with ASP, clearly.  Just trying to grasp the theory at the same time.

Thanks so much.