...

View Full Version : Using php variable in Javascript?



ruraldev
08-24-2010, 03:33 PM
SOLVED

I am trying to use a php variable in javascript.

At the moment I am using a fixed variable


$articleID = 5;

Then outputting it to the page to declare a javascript variable


var articleid = "<?php echo $articleID; ?>";

Then trying to us it within a string

"FlashVars", "fileURL=../uploadedfiles/+ articleid + .gpx&key=ABQIAAAAOQBC.........

Can anyone tell me what I am doing wrong? I am not very used to Javascript and perhaps I am going about it totally the wrong way.

Help!

Gordon:confused:

Dormilich
08-24-2010, 03:40 PM
in contrast to PHP JavaScript doesn’t look for variables in strings.

ruraldev
08-24-2010, 03:43 PM
Does that mean I am going about it totally the wrong way or is it not possible?

Dormilich
08-24-2010, 04:14 PM
you’re doing it wrong. you simple have to construct the result string.

ruraldev
08-24-2010, 04:35 PM
Does that mean what I should be doing is something like this:


var articleid = "fileURL=../uploadedfiles/<?php echo $articleID; ?>.gpx&key=ABQIAAAAOQBC........";

Old Pedant
08-24-2010, 07:06 PM
You could do it that way.

You could also do it the way you started:


articleid = "<?php echo $articleid;?>";
...
"FlashVars", "fileURL=../uploadedfiles/"+ articleid + ".gpx&key=ABQIAAAAOQBC........."



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum