Forum Moderators: coopster

Message Too Old, No Replies

Executing javascript from php

javascript php run executing

         

mrchipps

1:37 am on Oct 19, 2005 (gmt 0)



To all me mates, a grand hello.

I'm running a popular PHP forum on my server and wish to add a little holiday cheer to it, via javascript encoded bats that fly around your mouse pointer. Silly, yes I know, but I figured it would help me become a better programmer if I could only figure out how to execute the JS from my index.php.

Can I simply cut and paste the javascript into the php somewhere and hope for the best, or is this going to be a difficult task?

And, I'm using the PHPBB to run my forum. Any help would be greatly appreciated. (warning, I am sorta new at programming php).

[edited by: jatar_k at 3:13 am (utc) on Oct. 19, 2005]
[edit reason] no urls thanks [/edit]

mcibor

8:59 am on Oct 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can run javascript without any problems! PHP is server based, so what you do is create the js output as you do with html.

There are many ways of creating the output:

<?php
$a = 2;
?>
<script type="text/javascript">
<!--
var a = <?php echo $a;?>;
//-->
</script>

or
<?php
$a = 2;
echo "<script type=\"text/javascript\">
<!--
var a = $a;
//-->
</script>";

You just need to remember, that you can pass values from php to javascript, but not otherwise.
As I mentioned before, php is server based. JS is user based. To pass values from js to php you need to use POST or GET method.

Hope this helps you!
Best regards
Michal Cibor