SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2002
    Location
    KSA
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How send Variable from PHP to JavaScript ?

    I need to display the variable from PHP to ( POP ) JavaScript

    $mess = "ERROR .. Please Enter the name";

    Display ( $mess ) in POP Windows JavaScript

    Thanks

  2. #2
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,236
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    PHP Code:
    <?php
    $mess 
    'alert(\'Please Enter the Name\');';
    ?>
    <script type="text/javascript">
    <?php echo $mess;?>
    </script>
    Does that work?

  3. #3
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm really not sure what you want, but if you want to display a PHP variable in Javascript, just do this:
    Code:
    <script type="text/javascript">
    function myFunc(somevar)
    {
    	 var phpVar = <?=$mess?>;
    }
    </script>
    <?=$mess?> is what will echo the variable $mess into the javascript function.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*


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
  •