This is what we call external javascript too..
Anyway save your .js file as .php. For example, your js file will be named as file.php
The syntax to referencing a PHP file using external JavaScript is almost same as what we normally do for JS files:
<script type=”text/javascript” src=”file.php”></script>
where “file.php” is either an absolute or relative path to a PHP script instead of the usual .js file. Paramenters can also be passed to the PHP file by using the URL string:
<script type=”text/javascript” src=”file.php?id=3&name=hmmmsup”></script>
PHP Script can get these parameters using the global variable $_GET. I know, you may be wondering whats the catch here? Hmmm, actually there is no catch involved here, just some limitations. Since the PHP script is being invoked indirectly and via JavaScript, the final output of the PHP script should be a valid JavaScript. It can be considered as a dynamic .js file!
In the normal PHP script called inside a PHP page, the output is a raw HTML data and the source code can be modified using the script, but thats not the case with JavaScript invoked version though…Anyway there are loads of things which can be done using this!
ps: it had been a long day!

