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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Auto close window

Status
Not open for further replies.

hc1619

Programmer
Feb 17, 2004
62
0
0
NZ
I have a window which pops up from my site using javascript. In this window the user types in their message in a form and pushes the submit button.

WHat i want to happen is I'd like the confirmation page to close the window automatically... so the user types in their message.. .pushes submit.. and the window closes (but first the form must be posted to the new page, and THEn the window closes).

I've looked around and cant find much..and that which i have tried hasnt worked. Can someone let me know how this is done?

thanks!!
 
hc1619,

How about at the submit button, implement a onclick event like this.
[tt]
<input type="submit" onclick="self.close()" />[/tt]

regards - tsuji
 
but i need to process the form first on another page, and THEN close the window.
 
hc1619,

The principle is the same. In the handler, after all the processing done, issue self.close() to close the window.

- tsuji
 
could you give me code example please? (because everything I've tried doesnt seem to work)
 
hc1619,

This is some left over in my notes that may be enough to illustrate this. Name the close to submit just to make everybody happier as to demo the idea.

The original page:
Code:
<html>
<head>
<script language="javascript">
function winopen() {
	var owin=window.open("data_pop.htm","");
}	
</script>
</head>
<body>
<form name="frmname">
<input type="text" name="txtbx" value="default" /><br />
</form>
<button onclick="winopen()">open and select</button>
</body>
</html>
which open a data_pop.htm page:
Code:
<html>
<head>
<script language="javascript">
function winclose(obj) {
	var sret="";
	for (var n=0;n<obj.length;n++) {
		if (n==obj.length-1) {
			sret+=obj.item(n).checked;
		} else {
			sret+=obj.item(n).checked+",";
		}
	}
	self.opener.frmname.txtbx.value=sret;
	self.close();
}
</script>
</head>
<body>
<form name="frmname">
<input type="checkbox" name="chkbx" value="a">A</input>
<input type="checkbox" name="chkbx" value="b">B</input>
<input type="checkbox" name="chkbx" value="c">C</input>
</form>
<br />
<button name="closeit" onclick="winclose(document.frmname.chkbx);">close</button>
</body>
</html>
(I have not made thing look nicer.) Would this be enough to illustrate the mechanism?

- tsuji
 
Hmmmm i dont think this is what i need.

This is how i have it at the moment:

A user on my site clicks a link and it pops up a window (this is the only popup to occur). So no worries to here.

On this popped up page is a form. The user fills out the form.. pushes submit.. (STILL within the popped up page).. goes off to another page, processes the form.. and then i want to close the popup.

 
hc1619,

That's is very concrete. I like it. It's your turn to post code.

- tsuji
 
im such an idiot. my form posts to itself..runs the code and processes the form and then i redirect to another page.

on that page i put:

<body onLoad="window.close();">

and it worked.

cant believe i didnt try that before.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top