Gossamer Forum
Home : General : Perl Programming :

Javascript close window & submit

Quote Reply
Javascript close window & submit
Hi

I've got this javascript to close the window when button is pressed.

onClick="window.close()"

How can I get it to submit the form too. It doesn't seem to want to do this?

Thanks

- wil
Quote Reply
Re: [japh] Javascript close window & submit In reply to
try doing:
<form ... onSubmit="window.close()">

then putting in a <input type="submit">

Adrian
Quote Reply
Re: [brewt] Javascript close window & submit In reply to
Thanks, Adrian.

- wil
Quote Reply
Re: [brewt] Javascript close window & submit In reply to
That didn't work, unfortunately. Any more guesses?

- wil
Quote Reply
Re: [japh] Javascript close window & submit In reply to
OK. I'm now just submitting the form as usual and then redirecting the user to another page which has the following code:

Code:
<Script language="Javascript">
<!--
function CloseWindow() {
window.close;
}
-->
</script>

<body onLoad="CloseWindow()">

But the window still doesn't want to close. What am I doing wrong with the above code?

Thanks!

- wil
Quote Reply
Re: [japh] Javascript close window & submit In reply to
Brewt's version works perfectly well...
Quote Reply
Re: [japh] Javascript close window & submit In reply to
I realy don't think you can do this. As soon as you close() the window it stops the upload.
You could delay the closure of the window long enough for the upload to complete if you knew for sure how long that was.
Some uploads can take for ever when the trafic is bad.

Bob
http://totallyfreeads.com
Quote Reply
Re: [RedRum] Javascript close window & submit In reply to
No. It closes the window but it doesn't submit the information.

- wil
Quote Reply
Re: [lanerj] Javascript close window & submit In reply to
Yeah, I thought about going about this from the other angle, but the following code still doesn't work.

Code:
<script language="javascript">
function mySubmit() {
document.notify.submit()
</script>

<body onUnload="mySubmit()">

- wil
Post deleted by japh In reply to
Quote Reply
Re: [japh] Javascript close window & submit In reply to
Yes! Got it to work by redirecting to another page with the following code init:

Code:
<script language="javascript">
<!--
function closeWin() {
window.close();
}
-->
</script>

<body OnLoad="closeWin()">

Thanks for your help.

- wil

Last edited by:

japh: Jan 17, 2002, 3:25 AM
Quote Reply
Re: [japh] Javascript close window & submit In reply to
Why not just use:

<body OnLoad="window.close();">
Quote Reply
Re: [japh] Javascript close window & submit In reply to
Right, never thought of closing a window via a returned page. Good one, that's very usefull.

Bob
http://totallyfreeads.com