PHP variables in javascript ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tony@tony.com

    #1

    PHP variables in javascript ?


    Am I being a bit dense again?
    How do I use variables created in PHP with javascript?


    tony
  • Rik

    #2
    Re: PHP variables in javascript ?

    tony@tony.com wrote:[color=blue]
    > Am I being a bit dense again?
    > How do I use variables created in PHP with javascript?[/color]

    Echo them in a script block to the HTML.

    $variable = 'something';

    echo <<<JS
    <script type="text/javascript">
    var myVar = '$variable';
    </script>
    JS;

    Grtz,
    --
    Rik Wasmus


    Comment

    • pieter_hordijk@hotmail.com

      #3
      Re: PHP variables in javascript ?

      Is this what you mean???

      eg. <body onload="alert(' <?php echo $php_variable; ?>')">

      Comment

      • tony@tony.com

        #4
        Re: PHP variables in javascript ?


        Thanks pieter and rick... both useful to me.
        If there are other ways I'd be happy to see them too.

        thanks

        tony

        Comment

        Working...