Solved

Lifetime of HTML page after document.forms(0).submit()

Posted on 2013-05-30
4
401 Views
Last Modified: 2013-06-06
I cautioned a member of my staff who had something like  the following code:

function sub() {
	document.forms(0).submit();
	myfn();
}

Open in new window

"That line of code after after the 'submit' will never be executed," I said, because control is passed to the CGI page you're submitting to as soon as line 2 is executed," but sure enough, the thing works. In fact, some testing revealed that any code added to the end of the function "sub()" runs before the CGI page gets control (IE 9).

I can't find this documented anywhere, but is this expected behavior? I thought a Submit() was akin to an <a href> is that control is immediately passed to the "Action" Can someone please explain to me the lifecycle/flow of a form submission? When does the calling page with the form "die"?
0
Comment
Question by:nkialex
  • 2
4 Comments
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 250 total points
ID: 39209460
http://www.eventhelix.com/realtimemantra/networking/HTTP_Post.pdf
http://www.w3.org/TR/html401/interact/forms.html#h-17.13.3

so you're looking for delay of processing the form submission
this tcp/ip connexion is slow comparing executing a function (if the function don't have itself a slow process)

but you should use different logic and put myfn() before
0
 

Author Comment

by:nkialex
ID: 39223349
Actually, I'm not looking for a delay of form processing, but getting one regardless. The post seems to not be done until the function that contains the submit method completes! This I can't find documented anywhere. I know the mfn() should go before -- my question is, why does it work when it goes after?!
0
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 250 total points
ID: 39223364
That could depend on what you are submitting and how long it takes.  Control doesn't actually 'pass' until you get the response back from the server.  If you are uploading files, that could take a while.  Or if the server response is slow.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39226981
Actually, I'm not looking for a delay of form processing

Open in new window

You need to look for it because this is the answer of your question :
why does it work when it goes after?!

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Angular.js example vocabulary extensions 5 32
Centering Vertically 3 28
Add css and js to MVC Project not in project 9 27
is this a cms? 8 34
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now