Page 1 of 1

Passing a form variable using PHP and JavaScript

Posted: Thu Oct 30, 2003 6:04 pm
by THEMADGEEK
I am attempting to pass a form variable to a pop-up window using the javascript 'window.open' syntax to no avail. The window opens but nothing is passed.

Here is what I have can anyone show me my error?

In short here is the pertinent part of the window.open call...

Code: Select all

var win2 = window.open("page.php","Window2","height=350,width=500,menubar=no,resizable=no,scrollbars=no,status=no");
And here is the form portion...

Code: Select all

<form name="form1" id="form1" method="post" action="javascript:void(0);">

<input name="email" type="text" size="30" />

<input name="submit" type="image" src="img.jpg" onClick="popUpCenteredWindow2();" width="59" height="15" border="0">

</form>
Thanks in advance!

Posted: Thu Oct 30, 2003 7:04 pm
by Gen-ik
You will need to put the form variables onto the URL in order to get them to exist in a new window.

Here's an example...

Code: Select all

<head>

<script language="JavaScript">

function FormToWindow(form)
&#123;
	var e = form.elements;

	var url = "?";

	for(var i=0; i<e.length; i++)
	&#123;
		if(typeof e&#1111;i].name != "undefined" && typeof e&#1111;i].value != "undefined")
		&#123;
			if(e&#1111;i].value.length > 0)
			&#123;
				url += e&#1111;i].name + "=" + e&#1111;i].value + "&";
			&#125;
		&#125;
	&#125;

	url = url.substr(0, url.length-1);

	window.open("page.php" + url, "", "height=350,width=500,menubar=no,resizable=no,scrollbars=no,status=no"); 

	return false;
&#125;

</script>

</head>

<body>

<form method="post" onsubmit="return FormToWindow(this)"> 

<input name="email" type="text" size="30"> 

<input type="image" src="img.jpg" width="59" height="15" border="0" onclick="this.form.submit()">

</form> 
 
</body>