How to Force Clear Form Data on Back?
I don't know what I am doing wrong, or maybe it just can't be done, but I have tried everything. I tried using meta tags to clear cache, and several scripts that just didn't work out.
I have an email list subscribe form on the main page of a website.
On submit, it goes to a "thankyou confirmation" page, that pages has a "Go Back" button, that works.
It could also be a absolute url to go to instead of back, whichever will work!
When it goes back, the email address is still in the form field!
How do I get rid of that? It seems easy enough, but I can't figure it out.
Is it some lame feature of my browser to save the form data? If so, can I force it to purge that data?
You will be my best friend forever if you can end my suffering! TRhanks in Advance!
Hi,
try this in an onload event
document.getElementById( 'fieldid' ).value = '';
There is nothing between the 's.
Good luck skriptor
You could add
onload="document.forms['formName'].reset()"
to the opening BODY tag, this will reset the form every time the page is loaded or refreshed
The Silent One
The most dangerous thing in the world is an idea.
The most dangerous person in the world is one with an idea
Nope, that didn't work, the information is still in the form. It is like the page is not even reloading, so I am not sure if there was a way to make it. I can make it reload from a popup window, but I just can't from teh same window, very strange.
Ill make something here
PHP Code:
highestV = 5 ; //Highest Element here
for( tmp = 0 ; tmp <= highestV ; tmp ++)
{
document . getElementById ( 'element' + tmp ). value = '' ;
}
Last edited by blah1985; 07-23-2005 at 08:47 PM .
Yay this one worked! Fabulous thank you soooo much!
I just added onload="document.getElementById( 'email' ).value = '';
One question though, if I wanted to clear more than one field, what would be the syntax for that?
onload="document.getElementById( 'email','name','more' ).value = '';
Would that work?
no, ie, but I want it to work for ie and fx
function clearEm() {
var txtBoxes = document.getElementsByTagName('input');
for(var i = 0; i < txtBoxes.length;i++) {
txtBoxes[i].value="";
}}
that ones good to, unless you got other elements
Nope, that didn't work, the information is still in the form.
Did you change formName to the name of your form because it worked in IE6. Mozilla, Firefox, and NS7
The Silent One
The most dangerous thing in the world is an idea.
The most dangerous person in the world is one with an idea
Originally Posted by
sfranck
Yay this one worked! Fabulous thank you soooo much!
I just added onload="document.getElementById( 'email' ).value = '';
One question though, if I wanted to clear more than one field, what would be the syntax for that?
onload="document.getElementById( 'email','name','more' ).value = '';
Would that work?
Here's how to clear multiple elements by their Ids similiar to the way you are trying to do it:
Code:
onload="clearElementsById( 'email','name','more' );"
However, you need to define clearElementsById() first:
Code:
function clearElementsById(){
for(var i=0,a=arguments.length,el;i<a;i++){
el=(document.getElementById)?
document.getElementById(arguments[i]):(document.all)?
document.all[arguments[i]]:(document.layers)?
document[arguments[i]]:null
if("value" in el)el.value=""
else if("innerHTML" in el)el.innerHTML=""
}
}
Untested (note I write flawless javascript code 95% of the time)
Many thanks, this Java Script works fine, never got other body onloads to work
Originally Posted by
Ultimater
Here's how to clear multiple elements by their Ids similiar to the way you are trying to do it:
Code:
onload="clearElementsById( 'email','name','more' );"
However, you need to define
clearElementsById() first:
Code:
function clearElementsById(){
for(var i=0,a=arguments.length,el;i<a;i++){
el=(document.getElementById)?
document.getElementById(arguments[i]):(document.all)?
document.all[arguments[i]]:(document.layers)?
document[arguments[i]]:null
if("value" in el)el.value=""
else if("innerHTML" in el)el.innerHTML=""
}
}
Untested (note I write flawless javascript code 95% of the time)
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks