#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Location
    Barcelona
    Posts
    298
    Rep Power
    77

    Pass of variable from PHP to JavaScript


    I have posted this question to the JavaScripot forum but I think it is more related to PHP...

    I have this code

    PHP Code:
    <head>
      <title></title>        
      <script type="text/javascript">
        function newTitle(text)
        { document.title=text }
      </script>    
    </head>
    <body onload="newTitle('<? $acces[$lang]; ?>')">
    On doing that, the title top bar of the relevant window does not take the value located in $acces[$lang].

    Any suggestion?

    Thanks in advance!
    Pere
    www.casti2001.com
  2. #2
  3. No Profile Picture
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2003
    Location
    Indonesia
    Posts
    905
    Rep Power
    18
    PHP Code:
    <body onload="newTitle('<?=$acces[$lang]; ?>')">
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Location
    Barcelona
    Posts
    298
    Rep Power
    77
    Thank you Tommy.

    I already got from Adios in the JavaScript forum this solution...

    <body onload="newTitle(<? echo $acces[$lang]; ?> )">

    Therefore I understand that "=" and "echo" mean the same in this application. Isn't it?
    Pere
    www.casti2001.com
  6. #4
  7. No Profile Picture
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2003
    Location
    Indonesia
    Posts
    905
    Rep Power
    18
    yes
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    4
    Rep Power
    0
    Tommy's response is correct, but I think your PHP.INI file must be configured to have ASP_TAGS set ON.




    ==================================================
    http://badblue.com
    Free, tiny, easy to install PHP server for Windows
    ==================================================
  10. #6
  11. No Profile Picture
    Dissident
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Mar 2003
    Location
    New York
    Posts
    1,671
    Rep Power
    49
    <?= ?>

    is a special php tag that says to print out the contents of the tag.

    This shorthand can be convenient if you just need to print out one variable but won't work if you need to do any extended code (like for loops, if else statements, etc).

    the standard php tag...

    <?php ?>

    allows you to execute php code within it. In order to make something appear in your browser, you must print to standard out (which in this case is your browser). This can be done via the print statement or the echo statement.

IMN logo majestic logo threadwatch logo seochat tools logo