PHP echo with a javascript window.close()

I’d like to echo a PHP variable when a user clicks on a text link which closes the pop up window.

I have this for the link:

<a href="javascript:window.close();">Close window</a>

and am wondering where or if i can insert the

<?php echo $passFileName ?>

Is this possible or is there a better way to do this?

i’m not sure where you want to ‘echo’ this variable. in an alert maybe?

you could do it like this


<a href="javascript:window.close();" onClick="alert('<? php echo $passFileName; ?> ');">Close window</a>

remember php writes to your html file when you echo, so basically think of how you would do it statically, and then replace the dynamic value with a php echo

I think I should have explained more in my post, sorry.
I want the $passFileName to be picked up by another php page that is not displayed to the user and this in turn is picked up by an embedded Flash Application.
I can’t have the $passFileName passed to the page where the Flash is embedded as this would mean the page would have to be loaded again, thus reloading the Flash movie, and losing the current frame in the movie that the user was on (and all the information they’ve inputted so far in the movie).
So, what I want to do is have the user input data ($passFileName) into a javascripted pop-up window. This value is passed to another php page (pass.php) which the Flash movie loads variables from. I’ve been able to get variables I set in pass.php to show up in the movie but I really need pass.php to pick up the variable from the pop-up window (hence the echo from the pop-up when it closes) - or is this pie-in-the sky impossible?

(I’ve looked at transferring variables via javascript from a child window to a parent window on close, but the page the variables have to go to is not the parent, and cannot go the parent page where the Flash is embedded, as I explained earlier).

why not use a form with action=‘pass.php’ ?

I’d like to echo a PHP variable when a user clicks on a text link which closes the pop up window

You have a fundamental misunderstanding of how php works. php executes on the server. After the php code executes, the php code is removed from the page. The server then sends the page to the browser. When the browser receives the page, there is no php on the page; and a browser has no idea what php code is anyway. A browser understands what html is and what javascript is.

JRGould - thanks for your suggestion - i tried this, using a hidden field to pass $passFileName in a form with the action as pass.php, but pass.php wont pick it up - says $passFileName is undefined. I used this code:

 <form name="form1" method="post" action="pass.php">
 <input type="submit" name="Close Window" value="Close Window" onClick="window.close();">
<input name="passFileName" type="hidden" value="<?php echo $passFileName ?>">
      </form>

7stud - thanks for your explaination - I get why the page where the flash is embedded wouldnt pick up the variable, but I dont understand how I can pick up a variable from pass.php that I’ve set, but not a variable from pass.php thats passed from the pop-up.

where is the value of $passFileName supposed to be coming from? if it’s user generated in the pop up then your not going to get it to echo because by the time it’s displayed to the user php has finished executing.

it sounds like what your talking about is a simple form:

popup:


<form name="form1" method="post" action="pass.php">
<input type="submit" name="Close Window" value="Close Window" >
<input name="passFileName" type="text" value="user created value">
</form>

pass.php


<?
//do whatever you need to do with $_POST['passFileName'];
?>
<script type='text/javascript'>
window.close();
</script>