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

Open a popup from a submit button

Status
Not open for further replies.

gasca

Programmer
Apr 2, 2003
22
ES
Hi,

I want to open a popup window from a submit button but I don't know how to do it.
It needs to be a <input type=&quot;submit&quot;> because the form sends information to the popup.

I tried this:

1. Open the popup in the submit button:
<form action=&quot;&quot;>
<input type=&quot;submit&quot; onclick=&quot;...&quot;>. Doesn't send
the information.

2. Open the popup from a normal button
<input type=&quot;button&quot; onclick=&quot;...&quot;> The same.

3. <form action=&quot;window.open('popup.html',blabla)
Shows an error, I suppose the action must be only
an URL.

Any help?

Thanks.
 
You'll need to create two files (obviously), and in this example they should be called &quot;Parent.html&quot; and &quot;Child.html&quot;.

&quot;Parent.html&quot; contains:
Code:
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;>
<html>
<head>
	<title>The Parent...</title>
<script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;>
<!--
var values=new Array();
function ReadValues(){
	var theForm=document.forms[0];
	var count=0;
	for(var x=0;x<theForm.elements.length;x++){
		if(theForm.elements[x].type!=&quot;submit&quot;){
			// it's a value to pass...
			values[count++]=theForm.elements[x].value;
		}
	}
}
function Launch(){
	ReadValues();
	var win=window.open(&quot;Child.html&quot;,&quot;TheWin&quot;,&quot;&quot;);
	return false;
}
//-->
</script>
</head>
<body>
<form onsubmit=&quot;return Launch();&quot;>
<input type=&quot;text&quot; name=&quot;fname&quot;> <input type=&quot;text&quot; name=&quot;lname&quot;><br>
<input type=&quot;submit&quot;>
</form>
</body>
</html>

and &quot;Child.html&quot; contains:
Code:
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;>
<html>
<head>
	<title>The Child...</title>
<script language=&quot;JavaScript&quot;>
function GetTheValues() {
	var theOpener=window.opener;
	var theValues=theOpener.values;
	var msg=&quot;&quot;;
	for(var x=0;x<theValues.length;x++){
		msg+=&quot;Value &quot;+(x+1)+&quot;: &quot;+(theValues[x])+&quot;<BR>&quot;;
	}
	document.write(msg);
}
</script>
</head>
<body>
<script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;>
<!--
GetTheValues();
//-->
</script>
</body>
</html>

Basically you can access variables in another window, if you can get a handle to the window. In this case, I have used the window.opener object. :)

Hope this helps.

Pete.


Lotus Notes Web Developer / Aptrix (LWWCM) Consultant
w: e: Pete.Raleigh(at)lclimited.co.uk
 
Your suggestion is fine, but I forgot an important
detail. The data passed to the page is ASP data, that is,
I get the data from the child window with Request.Form Object.

You gave me a hint with the onsubmit() event I didn't remember it but inside Javascript you can't handle asp information I suppose.

The problem is: to open a popup window the only method I know is Javascript, but with javascript you can't handle asp information, and the only way to pass asp variables is putting the page inside the action=&quot;&quot; form option. Am I right?

Could it be something like:

<form action=&quot;child.asp&quot; onsubmit=&quot;resize()&quot;>

and resize() a function that sets the
size of the window opened with action?
 
Within the Child window you could always put a FORM containing only HIDDEN values. Once you have the data in the Child window, write these values to appropriate fields and then use a formName.submit() method to POST/GET the information to ASP.

Pete.


Lotus Notes Web Developer / Aptrix (LWWCM) Consultant
w: e: Pete.Raleigh(at)lclimited.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top