Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onSubmit="window.close();" question... 1

Status
Not open for further replies.

booboo0912

Programmer
Jul 31, 2002
75
US
I'm trying to troubleshoot a problem, which isn't always consistent, so I'm looking at different possiblities for the solution. Here's my set up:

I have a showModalDialog window/form with an input box and a submit button. My form tag looks like this:

<form name=&quot;myPage&quot; action=&quot;goto.asp&quot; onSubmit=&quot;window.close();&quot; method=&quot;post&quot;>

My input tag is the standard <input type=&quot;submit&quot; name=&quot;test&quot; value=&quot;Submit&quot;>

SOMETIMES, when a user hits the submit button, the data is sent to the database without any problems, the window closes, and everything looks good. OTHER TIMES, which I can't seem to duplicate to troubleshoot, when a user hits the submit button, the window closes, but the information hasn't been submitted to the database. No error message, nothing!

My question is this...since I'm using onSubmit=&quot;window.close();&quot; and action=&quot;goto.asp&quot; (which is the page that sends the info to the database) in the form tag, could it be possible that the window is closing before the action=&quot;goto.asp&quot; gets executed? What is the order of execution...which happens first, the onSubmit= or action=? Like I said, sometimes it works, other times it doesn't...is this a question of processor speed??? Or some other computer aspect that I'm not aware of?

Thanks in advance!
 
Um, won't

Code:
action=&quot;goto.asp;window.close();&quot;

work?

Curious,
[monkey] Edward [monkey]

&quot;Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!&quot; -- inventor of the cat door
 
Alternately, you could set a timeout:

Code:
action=&quot;goto.asp;settimeout(window.close();,3000);&quot;

Good luck!
[monkey] Edward [monkey]

&quot;Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!&quot; -- inventor of the cat door
 
I'm not sure the timeout will work. Or at best may be spiratic. Once the goto.asp starts to load into the window, all JavaScript in the old document will cease to execute. That's why you are getting intermittant results. Sometimes, the connection to your server might be slow enough to submit the data, then have JavaScript close the window before the response is received by the server. But if the response is received by the server almost instantaneously, it could negate any further JavaScript commands.

Why don't you place a JavaScript command in the post page goto.asp that closes the window. That makes perfect sense to me.

ToddWW
 
Is it possible the submit command isn't getting sent to the server, because the window.close() command happens first?

My showModalDialog window is what I want to close after the data is submitted to the database, which is always being closed, this isn't the problem. It seems like the submit command is where the failure is.

The goto.asp page contains my connection commands, my sql command to update the database, but since the goto.asp window opens, I also have the self.close() script to close the goto.asp page. I've tried naming the showModalDialog window, then referencing that window via the goto.asp page, but I couldn't get it to work, that's why I chose to use onSubmit=&quot;window.close()&quot;.

Any suggestions?? THANK YOU!!!
 
booboo0912,

i do something similar in my apps - ToddWW hinted at it:

at the end of goto.asp, put this:
[tt]
<%

rem this is the end of goto.asp code...
%>
<script language=&quot;javascript&quot;>
window.close();
</script>
[/tt]
=========================================================
if (!succeed) try();
-jeff
 
Hi Jeff...I do have the window.close() script at the end of my goto.asp page (well, actually I have self.close() ). Closing the window(s) is not a problem. My problem is: the window seems to be closing before the goto.asp page is executed. Sometimes data is submitted to the database, sometimes it's not...but the window(s) always close.

Once a user clicks that submit button...which occurs first?? Does the window close first, then all other Javascript commands end up not getting executed (like ToddWW mentioned)? Could this be why the information doesn't always get submitted to the database?

Thanks again!!
 
booboo0912,

your goto.asp page will be executed linearly...if the window.close() script is at the end, it will be the last thing executed. =========================================================
if (!succeed) try();
-jeff
 
addendum - my comment above is true provided you haven't wrapped the ASP code in a condition that may not allow it to execute, e.g.:
[tt]
<%
If Request.ServerVariables(&quot;REQUEST_METHOD&quot;) = &quot;POST&quot; Then
rem do stuff
End If
%>
<script language=&quot;javascript&quot;>
window.close();
</script>
[/tt]

if the page is submitted using GET, the ASP won't execute
=========================================================
if (!succeed) try();
-jeff
 
Hi Jeff! I don't think I'm explaining my question very well... I do have the following code on my goto.asp page:

<script language=&quot;javascript&quot;>
window.close();
</script>

and this script closes the goto.asp page...this works great.

My question lies within my <form> tag...

I have a showModalDialog window...in this window, I have a <form> to collect data from the user. My form tag contains the following:

<form name=&quot;myPage&quot; action=&quot;goto.asp&quot; onSubmit=&quot;window.close();&quot; method=&quot;post&quot;>

The onSubmit closes the showModalDialog window (and this works).

Is there a certain order the commands work in when dealing with a form? Does the action get worked first, or is the onSubmit event being worked first, then canceling the action= command b/c the window closes?

Does this make sense???

 
i would remove onSubmit=&quot;window.close();&quot; from your form tag since goto.asp will handle it.

=========================================================
if (!succeed) try();
-jeff
 
I would just take out the on submit event so your form tag is just

<form name=&quot;myPage&quot; action=&quot;goto.asp&quot; method=&quot;post&quot;>

then in your button have

<input type=&quot;button&quot; name=&quot;test&quot; onclick=&quot;gotoAsp()&quot;>

then add a javascript function like

fucntion gotoAsp()
{
document.forms[0].submit();
window.close();
}

I've used something like this often and it works fine.
 
Thank You BillyKrow!!! It seems like your solution would help eliminate my question as to which event gets executed first! I will try this and go from there...
Thanks again!
booboo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top