Welcome to WebmasterWorld Guest from 3.85.245.126

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP and Javascript Problem

     
8:32 am on Jun 30, 2004 (gmt 0)

Junior Member

10+ Year Member

joined:Apr 11, 2004
posts:71
votes: 0


the way my system is set up all my javascripts have to be in an external file .js

so i use HTML to include the js file

<script type="text/javascript" src="http://scroll.js"></script>

now in the java script file is

marqueecontent="<nobr><font face='Arial'><? echo $scroll?></font></nobr>"

the $scroll is set in another file which is included... but $scroll only displays when its set on the js file e.g

<? $scroll = bob;?>

how do i transfer my variable from the php and get it to display

many thanks :) dom

11:46 am on June 30, 2004 (gmt 0)

Full Member

10+ Year Member

joined:Jan 27, 2004
posts:222
votes: 0


The js is a separate file, which does not have access to the variables in the file which has the:
<script type="text/javascript" src="http://scroll.js"></script>

line.
One way to pass the value of scroll to the js would be to send is as a GET parameter. Something like:
<script type="text/javascript" src="http://scroll.js?scroll=some%20text%20here"></script>

Then in the .js file (if it set to be parsed as a PHP file) you can access it will be in the variable $_GET['scroll']
You will have to watch out for special symbols in the scroll text and convert them (for example a space to %20) so they don't get messed up.

12:34 pm on June 30, 2004 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member 10+ Year Member

joined:Aug 1, 2003
posts:815
votes: 0


As Mykel mentioned, you can set up the .js file to be parsed for PHP. You could pass the value along to the JavaScript with a session variable.

If you can't/don't wish to set the .js file up to be PHP parsed, you can have PHP read the .js file into a PHP variable, place the desired value into place (with a regex, perhaps) and echo the JavaScript to the PHP page. Note sure if this would be the fastest solution, though.