views:

411

answers:

5

I have some javascript menu code that works just fine from a separate directory. But, when I try to call the same .js files from within the same directory, it won't see the files.

The following works from another directory:

script type="text/javascript"> var vbImgPath="../00-Menu-Files/"

But, if I do this from within the same folder, how would I do it?

THE SOLUTION (edited this in after much experimentation):

I experimented A LOT!!! There is only ONE solution that ultimately worked:

"../00-Menu-Files/"

The SAME thing as from the other directory! Pretty strange that there is no other way to call this from within its own directory. But I cannot find another alternative that actually works.

A: 

Maybe you'd use:

script type="text/javascript"> var vbImgPath="00-Menu-Files/"

You may want to make this work anywhere by using absolute urls with a / at the beginning and the full path afterwards, ie.

script type="text/javascript"> var vbImgPath="/00-Menu-Files/"

Whether this works or not depends on your site's directory structure.

dylanfm
Nope, no go. Tried them both. Dang!
James Musser
By referencing all things (images in img tags, urls in anchors, scripts and so on) with their absolute path (/images/logo.png or /javascripts/script.js), things will always be found. It's much better than ../ing around the place and making things dependent on where they are called.
dylanfm
A: 

Tried both of those already, didn't work...

James Musser
What's the directory structure like?
dylanfm
A: 

I came up with a solution, but would prefer to keep the file in the same directory. I created a subfolder in the same directory with the image files for the menus called "MenuPHP", and then did this:

script type="text/javascript"> var vbImgPath="../00-Menu-Files/"

to push it up a directory and specify the name of the above directory. Solved the problem, but added another directory to the path. At least the files are all in the same vicinity, which was what I was after.

If anyone knows how to specify the same directory, please advise.

James Musser
you mean var vbImgPath="../MenuPHP/"
DrG
+1  A: 

Usually directories are like this:

../ one up

/ root directory

./ The current directory. However not adding anything to the front should mean the same.

Ralf
A: 

Also tried another solution which now seems to work, but didn't work earlier for some reason:

script type="text/javascript"> var vbImgPath="../00-Menu-Files/"

Same command as the other directory... oh well, it works!!!

James Musser