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 !

    Regards,
    floriano
     
    floriano, Sep 12, 2019 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,500
    Likes Received:
    4,460
    Best Answers:
    123
    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:
    74
    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:
    7,151
    Likes Received:
    1,656
    Best Answers:
    29
    Trophy Points:
    475
    #4
    Is the page saved as a .php page?
     
    qwikad.com, Sep 13, 2019 IP
  5. floriano

    floriano Well-Known Member

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

    sarahk iTamer Staff

    Messages:
    28,500
    Likes Received:
    4,460
    Best Answers:
    123
    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:
    74
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    113
    #9
    Thank you guys... Solved !
     
    floriano, Oct 28, 2019 IP
  10. JEET

    JEET Notable Member

    Messages:
    3,825
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #10
    @floriano
    Solved how? Kindly tell, because your original code was correct anyways...
     
    JEET, Oct 28, 2019 IP