I have two php files.

index.php

<html>
	<head>
		<script type="text/javascript">
			function openG()
			{
				window.showModalDialog('profile.php');
			}
		</script>
	</head>
	<body>
		<input type="button" value="Press" onClick="openG()"/>
		<?php 
			extract($_GET);
			if(isset($yes))
				echo $yes;
		?>
	</body>
</html>

and a profile.php file

<html>
<head>
		<script type="text/javascript">
			function woot()
			{
				window.close();
			}
		</script>
</head>
<body>
<form action=index.php method=get>
<input type=text name=yes />
<input type=submit value=Submit onClick="woot()" />
</form>
</body>
</html>

How would I be able to display $yes in the index.php page after the modal window of profile.php is closed? Or how would I be able to refresh the index.php page after profile.php page is closed?

demit. it works on IE but not on Fire Fox, Google Chrome and Safari. Damn these browsers. :P

Any help will be appreciated greatly. Thanks.

Instead of submitting form in the modal window what you can do is have a hidden element in the index.php file. Than on clicking the button in the modal window set the value in the textbox to this parent window's hidden element and than submit the parent window's form

index.php

<html>
	<head>
		<script type="text/javascript">
			function openG()
			{
				window.showModalDialog('profile.php', window); //Send the current window object as a parameter
			}
		</script>
	</head>
	<body>
		<form name="main_form" action="index.php" method="get">
			<input type="hidden" name="yes" /> <!-- A from with hidden element -->
		</form>
		<input type="button" value="Press" onClick="openG()"/>
		<?php 
			extract($_GET);
			if(isset($yes))
				echo $yes;
		?>
	</body>
</html>

profile.php

<html>
<head>
		<script type="text/javascript">
			function woot()
			{
				var xWin=window.dialogArguments;
				xWin.document.main_form.yes.value=document.popup_form.yes.value; //set the value in the opener windows hidden element
				xWin.document.main_form.submit();//submit the opener form
				window.close();
			}
		</script>
</head>
<body>
<form name="popup_form">
<input type="text" name="yes" />
<input type="button" value="Submit" onClick="woot()" />
</form>
</body>
</html>

Also 'showModalDialog' is not a standard JavaScript function. It was introduced in IE way back and Firefox has started supporting it since version 3. Chrome opens a non-modal window. Also can't predict its behavior in other browsers. So would suggest you to avoid using it if you want cross-browser compatibility. You can get modal windows in different javascript libraries like jquery, YUI etc.

It works! Thank you. Though I still need to study the code a bit. Can I ask for some online resources you know are good where I can study javascript? Thanks again, friend.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.