Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Oct 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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 09:01 PM. Reason: SOLVED

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,444
    Thanks
    13
    Thanked 361 Times in 357 Posts
    in contrast to PHP JavaScript doesn’t look for variables in strings.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #3
    New to the CF scene
    Join Date
    Oct 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Does that mean I am going about it totally the wrong way or is it not possible?

  • #4
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,444
    Thanks
    13
    Thanked 361 Times in 357 Posts
    you’re doing it wrong. you simple have to construct the result string.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #5
    New to the CF scene
    Join Date
    Oct 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Does that mean what I should be doing is something like this:

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

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,151
    Thanks
    80
    Thanked 4,557 Times in 4,521 Posts
    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.

  • Users who have thanked Old Pedant for this post:

    ruraldev (08-24-2010)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •