1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Include variable in javascript

Discussion in 'JavaScript' started by floriano, Sep 12, 2019.

  1. #1
    Hello,

    I am newbie in javascript, can anyone help me please?

    I want to add a variable in: var url
    here I want to replace:
    var url = "<?php echo $my_variable; ?>";

    this variable is used in many pages and for each page have a different name... is not fixed variable.

    Thanks in advance for any help !
    SEMrush
    Regards,
    floriano
     
    floriano, Sep 12, 2019 IP
    SEMrush
  2. sarahk

    sarahk iTamer Staff

    Messages:
    25,336
    Likes Received:
    3,478
    Best Answers:
    101
    Trophy Points:
    665
    #2
    That's how its done. Is it not working for you?
     
    sarahk, Sep 13, 2019 IP
  3. floriano

    floriano Well-Known Member

    Messages:
    71
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    113
    #3
    No
     
    floriano, Sep 13, 2019 IP
  4. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    5,987
    Likes Received:
    1,122
    Best Answers:
    22
    Trophy Points:
    400
    #4
    Is the page saved as a .php page?
     
    qwikad.com, Sep 13, 2019 IP
  5. floriano

    floriano Well-Known Member

    Messages:
    71
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    113
    #5
    Yes
     
    floriano, Sep 13, 2019 IP
  6. sarahk

    sarahk iTamer Staff

    Messages:
    25,336
    Likes Received:
    3,478
    Best Answers:
    101
    Trophy Points:
    665
    #6
    When you view source what do you see?
     
    sarahk, Sep 13, 2019 IP
  7. jstech2020

    jstech2020 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #7
    Is it inside <script> and </script> tag?
     
    jstech2020, Oct 24, 2019 IP
  8. sbenjamin81

    sbenjamin81 Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #8
    Is the JavaScript variable placed before attempting to access it?
     
    sbenjamin81, Oct 24, 2019 IP
  9. floriano

    floriano Well-Known Member

    Messages:
    71
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    113
    #9
    Thank you guys... Solved !
     
    floriano, Oct 28, 2019 IP
  10. JEET

    JEET Well-Known Member

    Messages:
    2,395
    Likes Received:
    132
    Best Answers:
    2
    Trophy Points:
    185
    #10
    @floriano
    Solved how? Kindly tell, because your original code was correct anyways...
     
    JEET, Oct 28, 2019 IP