0

Hey all,
i have been using php for past one month only and now im using javascripts with php too...
but my javascript functions have grown out of proportion ...
I want to make a SEPARATE file for JAVASCRIPT just like we do it for EXTERNAL CSS...

how can i do that and is it possible to make a seperate javascript file and call the functions from my php code...?

THNAKS

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by cwarn23
0

Simply give your javascript file a .php extension then php code may be used in the file. So for example your filename may be scripts.php and will display all of the required javascript using php.

0

Simply give your javascript file a .php extension then php code may be used in the file. So for example your filename may be scripts.php and will display all of the required javascript using php.

what i did is
i made a file xyz.js and placed all my java script functions and stuff in that
and then in my php file in the header tag (HTML) i used
<script type="text/javascript" src="xyz.js"> </script>
and its working....

what you said i was doing that already and i wanted to remove the javascript from my php file and make a separate .js file....

0

except you didn't change the extension. For example to include the javascript file you should use the following:

<script type="text/javascript" src="xyz.php"> </script>

Then in xyz.php you can process the javascript to your likings and even use something like the following method to include the javascript file.

<script type="text/javascript" src="xyz.php?id=1835&var=true"> </script>

So that way php code will work in the javascript file if that is what you want.


However if you want to include php functions and not javascript function into the php file such as custom defined php functions then the following is what you would use.

<?php
include('functions.php'); //no javascript
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.