Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Dec 2006
    Posts
    306
    Thanks
    24
    Thanked 0 Times in 0 Posts

    how to call to a function(it is in javascript) from a php

    Hi;
    I'd like to ask how i can call a function which it is Javascript from php. Thanks


    Code:
    <?php
    session_start();
    $_SESSION['check']=1;
    ?>
    <html>
    <head>
    <script type="text/javascript">
    function displaymessage()
    {
    alert("Hello World!");
    }
    </script>
    </head><body>
    <?php
      if ($_SESSION['check']==1)
         How i can call function displaymage()?????
      else
         echo "Bye";
       
    ?>
    
    </body>
    </html>

  • #2
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    You cannot directly call a js function from php. php runs server-side while js runs client-side.

    What you can do, is using your $_SESSION check, determine if the function should be called and, if so, echo the call to the function inside of the <body> tag (running it using the js on load event.
    John

  • #3
    Regular Coder
    Join Date
    Dec 2006
    Posts
    306
    Thanks
    24
    Thanked 0 Times in 0 Posts
    Thanks for your helpping.

    i will do like that
    echo "<BODY onLoad="javascript:displaymessage();">"


  •  

    Posting Permissions

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