www.webdeveloper.com
Results 1 to 13 of 13

Thread: How to Force Clear Form Data on Back?

  1. #1
    Join Date
    Jul 2005
    Posts
    6

    Question 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!

  2. #2
    Join Date
    Feb 2003
    Posts
    85
    Hi,
    try this in an onload event
    document.getElementById( 'fieldid' ).value = '';
    There is nothing between the 's.
    Good luck skriptor

  3. #3
    Join Date
    Apr 2003
    Location
    UK
    Posts
    2,203
    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

  4. #4
    Join Date
    Jul 2005
    Posts
    6
    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.

  5. #5
    Join Date
    May 2005
    Location
    US of A, Ohio
    Posts
    342
    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.

  6. #6
    Join Date
    Jul 2005
    Posts
    6
    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?

  7. #7
    Join Date
    Jul 2005
    Posts
    6
    no, ie, but I want it to work for ie and fx

  8. #8
    Join Date
    May 2005
    Location
    US of A, Ohio
    Posts
    342
    see above

  9. #9
    Join Date
    May 2004
    Location
    Manhattan NY
    Posts
    6,028
    function clearEm() {
    var txtBoxes = document.getElementsByTagName('input');
    for(var i = 0; i < txtBoxes.length;i++) {
    txtBoxes[i].value="";
    }}

  10. #10
    Join Date
    May 2005
    Location
    US of A, Ohio
    Posts
    342
    that ones good to, unless you got other elements

  11. #11
    Join Date
    Apr 2003
    Location
    UK
    Posts
    2,203
    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

  12. #12
    Join Date
    Jan 2005
    Location
    Los Angeles, CA
    Posts
    4,887
    Quote 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)

  13. #13
    Join Date
    Jan 2013
    Posts
    12

    Many thanks, this Java Script works fine, never got other body onloads to work

    Quote Originally Posted by Ultimater View Post
    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
  •  
HTML5 Development Center



Recent Articles