#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Posts
    14
    Rep Power
    0

    Angry Php And Javascript


    Are there any tutorials of getting PHP and Javascript working together? Php and Javscript are currently on the same page but javascript is in one place and php is in the rest.

    please help me.
  2. #2
  3. Super Genius
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Location
    Orlando, Florida
    Posts
    314
    Rep Power
    13
    You can't get them to talk together because PHP is server side and JavaScript is client side.

    You can, however, make PHP dynamicly write javascript into a page.
    Sleep is highly overrated.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Posts
    14
    Rep Power
    0
    Could you give me a small sample of code that would illistrate how to make php dynamically write javascript onto a page?

    thanks
  6. #4
  7. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    793
    PHP Code:
    <?php
    echo "<script language=\"javascript\">\n".
        
    "alert('This was written by php');\n".
        
    "</script>\n";
  8. #5
  9. Super Genius
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Location
    Orlando, Florida
    Posts
    314
    Rep Power
    13

    Here


    PHP Code:
    <?

    $foo 
    'Any random text string';

    if(empty(
    $foo)) {
        
    // $foo has no value
        
    echo "<script>\n";
        echo 
    "  document.writeln(\"You can't see this because the variable has a value!\");";
        echo 
    "</script>\n";
    }
    else {
        
    // $foo has a value
        
    echo "<script>\n";
        echo 
    "  document.writeln(\"\$foo: $foo\");";
        echo 
    "</script>\n";
    }

    ?>
    Just so you know, don't get in the habit of asking people to write your code for you. I don't mind if you need a small example and nothing more, but some people will get on to you about that.

    I'd suggest buying lots of books and read the php manual (www.php.net/manual/en).
    Sleep is highly overrated.
  10. #6
  11. Here, not there
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Posts
    312
    Rep Power
    13
    There is also some great info on php.faqts.com

IMN logo majestic logo threadwatch logo seochat tools logo