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

Recommended Answers

All 3 Replies

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.

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....

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
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.