Clear Textarea on Back Button>

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ryank
Forum Newbie
Posts: 11
Joined: Sat Jul 19, 2008 2:56 pm

Clear Textarea on Back Button>

Post 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
User avatar
tr0gd0rr
Forum Contributor
Posts: 305
Joined: Thu May 11, 2006 8:58 pm
Location: Utah, USA

Re: Clear Textarea on Back Button>

Post 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.
ryank
Forum Newbie
Posts: 11
Joined: Sat Jul 19, 2008 2:56 pm

Re: Clear Textarea on Back Button>

Post by ryank »

How would such a javascript work?
User avatar
tr0gd0rr
Forum Contributor
Posts: 305
Joined: Thu May 11, 2006 8:58 pm
Location: Utah, USA

Re: Clear Textarea on Back Button>

Post 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.
User avatar
xjake88x
Forum Commoner
Posts: 50
Joined: Sun Aug 01, 2004 7:05 pm

Re: Clear Textarea on Back Button>

Post 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>
 
Post Reply