Clear a form when user returns ?

I have a page / form on Wordpress that users complete then hit submit.  The page processes Properly and the user receives a thank you / acknowledge page.  

In the Form I have this code --
<script language="Javascript" type="text/javascript">
window.onbeforeunload = function () {
   // This function does nothing.  It won't spawn a confirmation dialog
   // But it will ensure that the page is not cached by the browser.
}
</script>

Open in new window


An on the Acknowledgement page I have this code to enable a Back button that will allow the user to submit another entry.  

<INPUT TYPE="button" VALUE="Back" onClick="history.go(-1);">

Open in new window


All works great, except that the data is being Cached on the first page, and when the user goes back to it the page contains what was previously entered instead of being reinitialized.  

Anyone have any suggestions on how to address this need differently ?

TIA --
LVL 15
PhonebuffAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
Instead of your input being a back button make it a link to the page. That will force a refresh of the input cache.

Also make sure you have a no cache set
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />

Open in new window

0
James RodgersWeb Applications DeveloperCommented:
if that doesn't solve the issue try turning autocomplete off on the form

<form autocomplete = "off"
0
PhonebuffAuthor Commented:
Nope -- Neither answer seems to solve the issue infact I could not get the site to do anything when I changed the back button ..
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

PhonebuffAuthor Commented:
Correction,  Julian's fix works, but it is REAL slow, compared to the history.go(-1).

<INPUT TYPE="button" class="largeButton"  VALUE="Back" onclick="javascript:window.location.href='http://xxxxxxx.xxxxxxxx.net'; return false;" >

Open in new window


An it means the HREF has to be updated for each site the code is used with ---

IS there a Variable that I can use instead of the Site Domain ?
0
Julian HansenCommented:
An it means the HREF has to be updated for each site the code is used with ---
This you get from HTTP_REFERRER

If it is slow then look to your code - but otherwise you don't have a solution.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PhonebuffAuthor Commented:
Julian --

  Might have closed it to soon --

<script language="JavaScript">  document.write(document.referrer); </script> 

Open in new window


Works and displays the URL correctly .

<INPUT TYPE="button" class="largeButton"  VALUE="Back" onclick="javascript:window.location.href='http://xxxxx.xxxxxx.net'; return false;" >

Open in new window


Also works correctly..

<INPUT TYPE="button" class="largeButton"  VALUE="Back" onclick="javascript:window.location.href="
<script language="JavaScript"> document.write(document.referrer) </script> 
"; return false; " >

Open in new window

                                                                                                     

But,  When I try and combine the two methods and  put it in the button it does not expand correctly --  

Any ideas ?
0
Julian HansenCommented:
Why not use an event handler with something like JQuery
<script src="http://code.jquery.com/jquery.js"></script>
<script type="text/javascript">
$(function() {
   $('.largeButton').click(function() {
      window.location = document.referrer;
   });
});
</script>

Open in new window

0
PhonebuffAuthor Commented:
You, mean besides the fact that it is beyond my current level expertise with HTML.  

===================

If I did this then what would the <INPUT...   Line look like ?

TIA --
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
WordPress

From novice to tech pro — start learning today.