Re: passing PHP variables to Javascript ...

From: Date: Thu, 20 Nov 2003 12:06:00 +0000
Subject: Re: passing PHP variables to Javascript ...
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-170401@lists.php.net to get a copy of this message
"Cpt John W. Holmes" <holmes072000@charter.net> wrote in message news:005301c3ad43$9e99f5d0$a629089b@TBHHCCDR... > From: "Kenn Murrah" <kenn@thebytebusiness.com> > > I need to be able to pass a PHP variable to a Javascript and can't > > figure out how to do it. In short, the Javascript win() statement is > > used open a page as defined in PHP -- i.e., $php_name = > > "http://www.somewhere.com/something/3.jpg" , a > > filename that was > > generated dynamically in PHP ... how do I pass that variable to my > > Javascript routine? > > <script language = "JavaScript"> > var mywin = '<?=$php_name?>'; > > win(mywin); > > </script> > > or something like that. > > ---John Holmes... Yes, is that simple, but if it doesn't work for you (because of the short tag <?= ) use the 'echo' or 'print' commands: [... php code ... ] ?> <script language = "JavaScript"> var mywin = '<?php echo $php_name; ?>'; win(mywin); </script> <?php [... more code ... ] - Good luck

« previous php.general (#170401) next »