faqts : Computers : Programming : Languages : JavaScript : Forms : TextAreas/TextFields

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

6 of 8 people (75%) answered Yes
Recently 6 of 8 people (75%) answered Yes

Entry

How can somebody enter something into a textarea, and visit that page again and it's still there?

Apr 10th, 2003 15:21
Jean-Bernard Valentaten, Malsar Sarmal,


You would need to set a cookie, save the content of the textarea in the 
cookie and read it upon revisit:
<html>
<head>
<title>MyCookie Example</title>
<script language="JavaScript">
  function setTA()
  {
    if (navigator.cookieEnabled)
    {
      if (document.cookie)
        document.forms[0].myTextArea.value = document.cookie;
    }
  }
  function setCookie()
  {
    if (navigator.cookieEnabled)
    {
      document.cookie = document.forms[0].myTextArea.value;
    }
  }
</script>
</head>
<body onLoad="setTA();" onUnLoad="setCookie();">
  <form ...>
    <textarea name="myTextArea" ...></textarea>
  </form>
</body>
</html>
Try it out, it should work. Please keep in mind that not everyone 
accepts cookies, especially if they don't expire (I won't describe how 
to create cookies that expire here, since you can find information 
about that by using www.google.com *g*), so this is not a reliable 
method. Also the cookie is not document bound, but domain bound.
HTH,
Jean