In article <56**************************@posting.google.com >,
ar********@yahoo.com (Jay) wrote:
Hi everybody !!
I am just wondering if Javascript and PHP can interact with each other?
I had the same problem with a feature I wanted to do with passing a
variable to a PHP script on a javascript popup and the PHP code to continue
executing the code in the popup depending on the variables passed to it.
I could not work out a solution, but after hours of searching (sorry didn't
bookmark the URL), I did find a solution. Here's the code I have.
Suppose that you want to call a popup, like I will. The script you want to
call will call a Javascript popup and pass the variables from the initial
click to the Javascript, which in turn will go to PHP to execute.
So suppose you have a page which will call a popup like this:
<script src="js/pics.js" type="text/javascript">
<!--
//-->
</script>
<body>
<a href="#" onclick="go_open('doit.php?&gallery=01&picID=01'); ">
</body>
This URL will go and run the javascript "pics.js" script which contains
something like:
<!--
function go_open(url)
{
window.
open(url,"Picture","width=50,height=50,toolbar=no, scrollbars=no,
status=yes");
}
//-->
Now, at the VERY beginning of the "doit.php" page - you have to write the
PHP / Javascript page like the following (before the <html> section).
<?PHP
// Import the variables from Javascript window.open() method to PHP.
$G-ID = $_GET['gallery'];
$P-ID = $_GET['picID'];
?>
//-->
</script>
<head><title>Popup</title></head>
<body>
Normal HTML page here mixed with PHP to make use of the vaiables.
Now later on in the page, you can then call the variables for $G-ID and
$P-ID as you have imported them using Javascript and PHP.
Complicated, but it does work.
Dariusz