remember form field input over reloads

C

coffee_man

Hi,
I have a page with a form. This form has an input field <textarea>. I
use it to have my users enter text and on form submit it gets inserted
into a db.
Initially there is some standard text shown in the <textarea> ("please
type comments here"). The user types some text, _doesn't_ do a submit,
continues to work. Only when he's finished working, he does a submit.
It's a time-tracking system so it also keeps track of start and
endtimes. Thats why.

So far so good.

Now every 20 minutes I do a refresh of the page (meta tag http refresh
etc). What happens: the text the user typed in gets replaced with
custom text! (remember, he didn't do a submit yet so there's no text
from the db to show). Now I wonder:

Can I somehow save the text user typed in the textarea? - maybe
onBlur=""
Can I save this text then somewhere locally? - Maybe in a hidden field?
Can I have the <textarea> show the contens of this hidden field? - this
would be either the standard text or - if user typed something - the
typed text.
How do I do this?

Thanks!
 
E

Erwin Moller

coffee_man said:
Hi,
I have a page with a form. This form has an input field <textarea>. I
use it to have my users enter text and on form submit it gets inserted
into a db.
Initially there is some standard text shown in the <textarea> ("please
type comments here"). The user types some text, _doesn't_ do a submit,
continues to work. Only when he's finished working, he does a submit.
It's a time-tracking system so it also keeps track of start and
endtimes. Thats why.

So far so good.

Now every 20 minutes I do a refresh of the page (meta tag http refresh
etc). What happens: the text the user typed in gets replaced with
custom text! (remember, he didn't do a submit yet so there's no text
from the db to show). Now I wonder:

Can I somehow save the text user typed in the textarea? - maybe
onBlur=""
Can I save this text then somewhere locally? - Maybe in a hidden field?
Can I have the <textarea> show the contens of this hidden field? - this
would be either the standard text or - if user typed something - the
typed text.
How do I do this?

Thanks!

Hi Coffeeman,

The easiest way is to remove the http-refresh header and replace the logic
with Javascript.

But first: WHy do you refresh the page? Are you circumventing a
sessiontimeout?
If you are worried about session loss with your server while the webpage is
open, a simple refresh every 20 minutes on some dummypage in a hidden frame
will keep the session alive, while your mainpage stays intact.

Have a look at setTimeout() function to program an event in the future.

Hope this helps.

Regards,
Erwin Moller
 
C

coffee_man

WHy do you refresh the page? Are you circumventing a
sessiontimeout?
yes!
Hope this helps.
Works great! thanks for the tip.

Anyway, what if I want to do this in another situation? How do I
remember input in a textArea on blur?
 
E

Erwin Moller

coffee_man said:
Works great! thanks for the tip.

Anyway, what if I want to do this in another situation? How do I
remember input in a textArea on blur?

Hi,

Getting the value is simple:
documnet.forms.yourformname.yourtextfieldname.value contains it.

How to remember?
Well, the problem is that javascript is limitted to one page.
If you refresh the page, the info that javascript held is gone.
If you need to remember values, you have to make a window that does not
disappear.

A straightforward solution could be: use frames: one hidden (height 0) and 1
normal as you do now.

You can put javascript in both the framedefinitionpage, or in the hidden
frame.
I would suggest you put it in the framedefinitionframe, in that way you will
have the hidden frame available for posting data to your server.

If you want to acces the framedefinitionpage from your current page, use
parent.etc


Now you have a few option. For example: use onUnLoad() to get the value of
the textfield and store it in the parent frame.
Or maybe onBlur. I never used onBlur in this context, so I have no advise.
Or maybe poll the value of the field every second, but that might be a
little over the top.

Hope this helps.

Good luck.

Reagrds,
Erwin Moller
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top