Question:

Curious PHP/Javascript

by  |  earlier

0 LIKES UnLike

I have html as include files within my php code. Now I would obvouisly put the Javascript into my HTML, but is there a way i could call a Javascript function using PHP?

 Tags:

   Report

4 ANSWERS


  1. Easy !

    Normally you do that to call a javascript:

    <script type="text/javascript">

    here a javascript

    </script>

    Now use this:

    <script type="text/javascript">

    <?php echo "here a javascript"; ?>

    </script>


  2. Script block...

    <html>

    <head>

    <title>x*x</title>

    <script type="text/javascript">

    <?php echo $myScript; ?>

    </script>

    </head>

    <body>

    </body>

    </html>

    Define $myScript (or whatever name you choose) with the JavaScript.

  3. The JavaScript resides on the client, the PHP on ther server, so no not directly.  A workaround: You could in PHP insert a script block into the HTML that will call your JavaScript.

    Script block would be a block of JavaScript.  So the PHP would add JavaScript into the HTML programmatically.

  4. I don't think so...that would be pretty cool if you could though.
You're reading: Curious PHP/Javascript

Question Stats

Latest activity: earlier.
This question has 4 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.