hello .. there is a weird problem in a website that im developing.. the problem is i cant a call external javascript if its located in a folder.. but if i put that in the directory where the index.php is located also i am able to call the javascript..

sample problem..

SCRIPT language="JavaScript" SRC="js/jxt1.js"></SCRIPT>

the jtxt1.js is located in js folder

but if i use this code

SCRIPT language="JavaScript" SRC="jxt1.js"></SCRIPT>

i unable to call this javascript because this javascript is located in the directory with the index.php i am unable to call it..

it also happens whenever i use require and include php.. so all my files are all located in one folder..

7 Years
Discussion Span
Last Post by scaiferw

One thing I can guarantee is that this has nothing to do with PHP, and everything to do with relative/absolute URLs, and how you are using them in your HTML code.

For one thing, I am unclear on where this PHP code you are showing comes from - is it from this index.php file you are mentioning? Is another PHP file including/requiring the file that contains this code?

Do you have a link where we could take a look at this? It should be a really easy fix, but there doesn't seem to be enough information here to convey exactly what is going on.


Because your source is js/jxt1.js instead of /js/jxt1.js, we know that this is a relative address.

What your code is saying is that the /js/ folder is a 'child' of whatever folder this page is executing from.

Adding the slash before "js/jxt1.js" as in /js/jxt1.jswould say that /js/ is under (a child of) the root of the website. ../js/jxt1.js would say that /js/ is a 'sibling' folder, i.e. a child of the parent folder. ../../js/jxt1.js would say that it is a child of the parent folder of the parent folder. I would probably never let it complicated, that's asking for grief.

Try putting a leading slash, /js/jxt1.js, you might find that solves the problem. Either way, SikoSoft was right, this is a relative addressing issue.

By the way, you're using some deprecated coding conventions, which may come back to bite you. Running your code throught the validator at validator.w3.org will cure all manner of ills.

Try this;

<script type="text/javascript" src="js/jxt1.js"></script>

Hope that helps.

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.