Including javascript code in echo statement

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jishcem
Forum Newbie
Posts: 12
Joined: Tue Nov 10, 2009 11:48 pm

Including javascript code in echo statement

Post by jishcem »

I would like to call a Javascript function which performs some Ajax operations. And I would like to call it in serverside using PHP echo statement. Is that possible? If not is there any options?

Any help is very much appreciated.

Thank you, Ajeesh
User avatar
N1gel
Forum Commoner
Posts: 95
Joined: Sun Apr 30, 2006 12:01 pm

Re: Including javascript code in echo statement

Post by N1gel »

The following will include a Javascript file and then you can just call the functions.

Code: Select all

echo "<script type='text/javascript' src='javascript.js'></script>";
I have found it helpful to do this in the past while developing to stop the file from being Cached

Code: Select all

echo "<script type='text/javascript' src='javascript.js?".Date("d/m/Y H:i:s")."'></script>";
Post Reply