Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"saving" textarea content so it appears on page refresh

Status
Not open for further replies.

janelange

Technical User
Jun 12, 2003
45
0
0
US
Is it possible to store the value of a textarea (i.e. what's written in it) or other form elements so that they do not "disappear" if the page is refreshed?

Thanks,
Jane L.
 
You can save it to document.cookie

In it's most basic form:
Code:
function save(){
document.cookie = forms[0].myTextarea.value;
}

window.onunload = save;

You can load the data by inversing the syntax.

--Glen :)

Memoria mihi benigna erit qui eam perscribam
 
Thanks for the input.

I don't know if this is out of the scope of this forum, but do you think there might be a way to implement this using a combination of JS and PHP? I'm not sure I want to go with cookies.

Jane

 
You can submit data to the server by a number of common gateway interface mechanisms (i.e. QUERY_STRING, POST_DATA, PATH_INFO) but I don't think these will work with a page refresh.

--Glen :)

Memoria mihi benigna erit qui eam perscribam
 
Me neither believe that query string will work at refreshing the page.]

But with refresh you could redirect the use to the same page, adding the query strings.
If the textarea is empty, it will remain empty, else its value will be the retrieved string.


-bclt
 
Jane,

The only way to do what you have asked over a page refresh, with any degree of cross-browser compatibility, is using cookies (with a solution like the one Glen gave).

As you are refreshing the page, not submitting a form, then PHP / form code will be useless.

This, of course, assumes you meant "refresh" instead of "submit" (i.e. the user presses their refresh button). This also assumes that their browser will support the onunload or onbeforeunload events. If they do not, there isn't really any way you will manage this.

Dan

[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top