Page 1 of 1

Clear Textarea on Back Button>

Posted: Thu Feb 04, 2010 1:04 pm
by ryank
He, I've got an html textarea in my php code with an initial value "enter description here..." The problem is when the user leaves the page and clicks the back button instead of the initial value the text area has what was previously written in it as a value. How can I make the browser forget these values as soon as you leave the page? I was able to do this with the text boxes in the form by adding autocomplete="off" to the form tag but that doesn't seem to be workign for the text area (and yes I did also try adding autocomplete="off" to the textarea tag too).

Any help is much appreciated,
-Ryan

Re: Clear Textarea on Back Button>

Posted: Thu Feb 04, 2010 2:44 pm
by tr0gd0rr
The simplest thing is to change it to "enter description below."

You could maybe do something hackish like an javascript window.onunload function that clears the box.

Re: Clear Textarea on Back Button>

Posted: Thu Feb 04, 2010 5:57 pm
by ryank
How would such a javascript work?

Re: Clear Textarea on Back Button>

Posted: Fri Feb 05, 2010 1:31 pm
by tr0gd0rr

Code: Select all

window.onunload = function() {
  // get a reference to the textarea by using getElementById
  // set the element's value property
}
You may need to use onbeforeunload, I don't know.

Re: Clear Textarea on Back Button>

Posted: Fri Feb 05, 2010 3:23 pm
by xjake88x
Most solid way is to load the default value into it when the page loads

Code: Select all

 
<input type="text" id="mybox" />
<script type="text/javascript">document.getElementById('mybox').value='Some default value';</script>