Question

Auto Submit Form & Back Button disable

Asked by: Ellmb122

Hi Guys,

I've been wrestling with this for a while but I can't figure out what's wrong with it.

I am trying to send details through a form, this info is sent to a second page which combines that data with data from a database and the page is autosubmitted to a processing script. The problem is, when the user clicks the back button on the last page they are taken to the second page and the details are resent. I need to delete the second page from the browsers history so they can't go back to it.

I've used a previous thread from experts-exchange.com for the solution, but it didn't work -

http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_20282674.html

I've used this script, but when the form on my page is automatically submitted, the action of the form doesn't seem to work - the next page is '/undefined' e.g. www.myurl.com/undefined.

I've knocked up a quick example to show you what is happening in the most simple form.

http://www.bigwebhost.net/ee_examples/firstpage.htm

When you visit this page, click the send button and it takes you to the second page which includes the script as shown below;

<script language="javascript">
function firstrun()
{
  document.forms[0].submit();
  location.replace(this.href);
  return false;
}
</script>

########### in the body tag ################

<body onload = "firstrun()">

##################################

I have disabled the onload function on this page - http://www.bigwebhost.net/ee_examples/secondpage_code.php to show you the code that is on the second page.

it auto submits the form but the action of the form doesn't seem to work. The back button problem is solved but the details aren't sent through to the script.

I hope all of this is clear, if not I can explain further. Also, please don't provide any solutions in PHP, the pages will eventually be uploaded to an ASP server so if you could provide the solution in Javascript that would be a great help.

Thank you.

Elliott.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2003-09-12 at 03:14:18ID20736802
Tags

disable

Topic

JavaScript

Participating Experts
4
Points
500
Comments
17

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. auto submit
    hi, how would one out submit a page in asp ? i am passing parameters to it and the user will never actually see this page it will run in the back but one it recieves certain values it must auto submit it self. Possible ? thanks.
  2. Auto Fill and Submit Web Form
    Hi, I have written a delphi 7 procedure to auto fill a website php form. After the program has filled in the user and password. I cannot work out how to auto submit the form. Here is the HTML code. <form action="members.php" method="post" etc ///t...
  3. onload page submit form
    HI experts, I have this bit of code that I would like it to automatically submit when loaded.... function form() { $ID = $_GET['ID']; echo '<table align="center" width="75%" bgcolor="'.$this->bgclr.'" border="'.$this->bordr.'&q...
  4. PHP if (submit)
    Below is code from the JSRS 'Select Demo'. I want the result to be placed into select.php (below the dropdown boxes). I have replaced result.php with select.php. I have written query code to printout the mankeName field as practice. My question is where do I place the if(subm...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: ZvonkoPosted on 2003-09-12 at 03:55:24ID: 9344884

Change two things:

1.) In this page http://www.bigwebhost.net/ee_examples/firspage.htm add this in the head section:
<head>
<title>...</title>
<script>
history.go(+1);
</script>
<head>


2.) In this page http://www.bigwebhost.net/ee_examples/secondpage_code.php change this function:
function firstrun(){
  document.forms[0].submit();
  setTimeout("location.replace(this.href)",10);
  return false;
}


And check the spelling of this URL:
http://www.bigwebhost.net/ee_examples/script.pl


Good luck,
Zvonko

 

by: Ellmb122Posted on 2003-09-12 at 04:13:58ID: 9344949

Hi Zvonko,

Thanks for your reply. Tried that, still got the same error message.

I made the changes as instructed and uploaded them to a different directory,

http://www.bigwebhost.net/ee_examples/zvonko/firstpage.htm

as you can see the, the action of the form is not going through (same as before) and the back button is also not working.

 

by: mplungjanPosted on 2003-09-12 at 04:20:19ID: 9344977

this.href is supposed to be what?

 

by: ZvonkoPosted on 2003-09-12 at 04:20:55ID: 9344981

I can not go back from the http 500 error page. Do you?

And that http 500 error is not because of JavaScript is doing anything. Your perl function refuses access.
I mean this as perl function:
<form name="form1" method="post" action="http://www.bigwebhost.net/ee_examples/script.pl">

 

by: ZvonkoPosted on 2003-09-12 at 04:25:04ID: 9344990

You are right Michel, I did not test.

Correction:

2.) In this page http://www.bigwebhost.net/ee_examples/secondpage_code.php change this function:
function firstrun(){
 document.forms[0].submit();
 setTimeout("location.replace(location.href)",10);
 return false;
}

(also not tested and has also no meaning. It reloads the actual URL)
Anyway does the submit() response overwrite the page and loaction.

And put this history.go(+1) also in this page head:
http://www.bigwebhost.net/ee_examples/secondpage_code.php



 

by: ZvonkoPosted on 2003-09-12 at 04:27:20ID: 9344998

Reading my post I noticed what nonsense I have posted.
Reloading of a php page which is automatically sending it submit() again and again!

The only good thing is that this did not work :-)

 

by: Ellmb122Posted on 2003-09-12 at 04:27:42ID: 9345000

Zvonko,

When I click the link to the pages with your changes on - http://www.bigwebhost.net/ee_examples/zvonko/firstpage.htm and click submit it takes me straight to a 404 page and http://www.bigwebhost.net/ee_examples/zvonko/undefined is displayed in the address bar and I can't use the back button because of the history.go(+1); script on the first page.

I don't get the 500 error.

there's nothing wrong with the script, click it direct - http://www.bigwebhost.net/ee_examples/script.pl

 

by: ZvonkoPosted on 2003-09-12 at 04:33:02ID: 9345022

Oh, and because I am one of top experts also on php ta (hello Michel) here my suggestion how to solve your resubmit problem.

Create a hidden field with a default value in the form of http://www.bigwebhost.net/ee_examples/zvonko/secondpage.php3
If the $_REQUEST['herenameofthehiddenfield']=="theDafaultValue" then do not print the <form> to the browser. That's all.

 

by: ZvonkoPosted on 2003-09-12 at 04:35:24ID: 9345030

Sorry, now clicking the url on this page works. I copied the url before in browsers url field and got an 500 error.

But try this php <form> suppression method. This is the best way to prevent form resubmit.

 

by: Ellmb122Posted on 2003-09-12 at 04:36:35ID: 9345036

Hi,

Thanks for your help, but I'm getting a bit confused with the last couple of posts fellas,

if we go back to the original problem, the script that i started with seems pretty good;

 location.replace(this.href);
 return false;

seems to be the area that causes the problems. I am open to all suggestions but i can't use PHP because the pages will be uploaded to an ASP server.

 

by: ZvonkoPosted on 2003-09-12 at 04:42:27ID: 9345063

Ok, the let us focus on that.

Definitely is this.href not a valid object.
Perhaps does this assignment of an error to a window location prevent of back and forth of pages, but it is definitely an error.

So if you can confirm that history.go(+1) works for you, then is this the solution. Simply add that line in every page which is forbidden to be reached from successor pages.


 

by: Ellmb122Posted on 2003-09-12 at 04:50:48ID: 9345099

The problem is not the back button, the actual script at the start of this post works fine for that, it deletes the second page from the browsers history and they can't go back to it, that's great. I just need to combine this with the autosubmit function for the form.

 

by: andres101Posted on 2003-09-12 at 06:38:39ID: 9345746

this seems to easy to be true, but it worked for me.
just add:
<SCRIPT LANGUAGE=javascript>history.go(+1);</SCRIPT>
to the head section of your page with the form on. users will not be able to go back. as soon as they do, they will just get taken back to the "after submit" page.

 

by: Ellmb122Posted on 2003-09-12 at 06:51:29ID: 9345835

Andres101,

Thank you for your suggestion. That works, the information is not resent but the visitor remains locked on the "after submit" page, is there any way we can make the script say something like;

if history.go(+1) is not blank then
   history.go(-1)
end if

(i don't know how to write JS)

this way, when we went back to the form page it would take them back another page?

I really appreciate everyone's help.

 

by: devicPosted on 2003-09-14 at 00:59:06ID: 9356189

hi Ellmb122,

1. You can on the second page set coockies, and if user has already cookies then Response.Redirect("where.asp")
2. Maybe in this situation is good solution with popup? Why not?
3. In every page (with submits) you disable caching
<%
   Response.CacheControl="no-cache"
   Response.AddHeader "Pragma","no-cache"
   Response.Expires=0
%>
and then ask for Request.ServerVariables("HTTP_REFERER")



 

by: andres101Posted on 2003-09-15 at 00:08:48ID: 9360822

no, don't think so. why not have "Back" link on your page that takes them back two pages, which i think is what you want:

<a href="javascript: void(0); history.go(-2);">Back</a>

 

by: Ellmb122Posted on 2003-09-16 at 12:15:06ID: 9372725

Hello,

I managed to sort the problem out myself with the help of the following URL.

http://www.4guysfromrolla.com/webtech/012600-1.shtml

The force refresh and cookie idea from devic and history.go(-2) code that andres101 provided also helped me on my way so i'm splitting the points.

Cheers.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...