Solved

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

Posted on 2013-05-30
4
399 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
Comment Utility
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
Comment Utility
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 82

Accepted Solution

by:
Dave Baldwin earned 250 total points
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

744 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

16 Experts available now in Live!

Get 1:1 Help Now