Jump to content

submit form to parent/main window from child window, FireFox 2.0


pakenney38

Recommended Posts

THE GOAL: Open child.php with the link on main.php. Fill out the form on child.php and submit the form variable back to main.php in the window that is already open. Close the window for child.php automatically after it submits the form. Display the contents of the variable on main.php.

 

THE PROBLEM: This is just a little test that I am putting together to incorporate into a larger project. I have had many years of experience with HTML and a couple with PHP, but I am starting to jump into combining this with Javascript and of course now I am running into browser specific issues. The following code works in IE 7 fully, but does not display the variable back on main.php using Mozilla 2.0. Possibly, the form variable is never even sent to the page (no way to prove or disprove that with my skill level).

 

[main.php]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript" language="javascript">

self.name = 'main';

</script>

<style type="text/css">
<!--
.style1 {font-family: Verdana, Arial, Helvetica, sans-serif}
-->
</style>
</head>

<body>
<a
href="child.php"
target="child"
onclick="window.open('child.php', 'child'); return false" class="style1">link</a><br /><br />
<font class="style1">
<?PHP
$textfield = $_POST['textfield'];
echo $textfield
?>
</font>
</body>
</html>

 

[child.php]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<SCRIPT LANGUAGE="JavaScript">

function closeWindow()
{
//Firefox
if (navigator.appName == 'Netscape')
{
window.open('', '_self', '');
window.close();
}
else //Internet Explorer
setTimeout("WB.ExecWB(45,2)",0);
}

</SCRIPT> 
<OBJECT ID="WB" WIDTH="0" HEIGHT="0" CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2">
</OBJECT> 
<style type="text/css">
<!--
.style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-weight: bold;
}
-->
</style>
</head>
<body>
<form action="main.php" method="post" name="form1" target="main" id="form1" onsubmit="closeWindow()">
  <label><span class="style1">Enter Variable</span>
  <input type="text" name="textfield" />
  </label>
  <p>
    <label>
    <input type="submit" name="Submit" value="Submit" />
    </label>
  </p>
</form>
</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.