Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-24-2010, 03:33 PM   PM User | #1
ruraldev
New to the CF scene

 
Join Date: Oct 2009
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
ruraldev is an unknown quantity at this point
Using php variable in Javascript?

SOLVED

I am trying to use a php variable in javascript.

At the moment I am using a fixed variable

PHP Code:
$articleID 5
Then outputting it to the page to declare a javascript variable

Code:
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

Last edited by ruraldev; 08-24-2010 at 08:01 PM.. Reason: SOLVED
ruraldev is offline   Reply With Quote
Old 08-24-2010, 03:40 PM   PM User | #2
Dormilich
Senior Coder

 
Dormilich's Avatar
 
Join Date: Jan 2010
Location: Behind the Wall
Posts: 2,855
Thanks: 9
Thanked 288 Times in 284 Posts
Dormilich is on a distinguished road
in contrast to PHP JavaScript doesn’t look for variables in strings.
__________________
please post your code wrapped in [CODE] [/CODE] tags
Dormilich is offline   Reply With Quote
Old 08-24-2010, 03:43 PM   PM User | #3
ruraldev
New to the CF scene

 
Join Date: Oct 2009
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
ruraldev is an unknown quantity at this point
Does that mean I am going about it totally the wrong way or is it not possible?
ruraldev is offline   Reply With Quote
Old 08-24-2010, 04:14 PM   PM User | #4
Dormilich
Senior Coder

 
Dormilich's Avatar
 
Join Date: Jan 2010
Location: Behind the Wall
Posts: 2,855
Thanks: 9
Thanked 288 Times in 284 Posts
Dormilich is on a distinguished road
you’re doing it wrong. you simple have to construct the result string.
__________________
please post your code wrapped in [CODE] [/CODE] tags
Dormilich is offline   Reply With Quote
Old 08-24-2010, 04:35 PM   PM User | #5
ruraldev
New to the CF scene

 
Join Date: Oct 2009
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
ruraldev is an unknown quantity at this point
Does that mean what I should be doing is something like this:

Code:
var articleid = "fileURL=../uploadedfiles/<?php echo $articleID; ?>.gpx&key=ABQIAAAAOQBC........";
ruraldev is offline   Reply With Quote
Old 08-24-2010, 07:06 PM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,992 Times in 3,961 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
You could do it that way.

You could also do it the way you started:
Code:
articleid = "<?php echo $articleid;?>"; 
...
"FlashVars", "fileURL=../uploadedfiles/"+ articleid + ".gpx&key=ABQIAAAAOQBC........."
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
ruraldev (08-24-2010)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:54 AM.


Advertisement
Log in to turn off these ads.