SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2010
    Posts
    453
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    js var from php var

    Isn't this how you turn a php var into a js var?
    Code:
    var url = "<?php echo $_SESSION['url'] ?>";
    if so, why does the php code display in an alert() instead of the value of $_SESSION['url']?

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,683
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by nichemtktg View Post
    Isn't this how you turn a php var into a js var?
    Code:
    var url = "<?php echo $_SESSION['url'] ?>";
    if so, why does the php code display in an alert() instead of the value of $_SESSION['url']?
    That would be due to the HTML page not being interpreted as a php file.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

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