View Full Version : javascript roll over funny phenomenon

9th April 2009, 11:19 AM

I have a piece of html like below, and it's working. But the problem is the part that I pass the variable of file path on <input id="but" type="button" value="<" onclick="mainwin('main_img', 'ima/2.jpg');" />

It seems only the file path start with "img" will work, I tried image/1.jpg, 1/1.jpg .... or even img/1/1.jpg, none of them will load the image. Javascript seems to treat it like a broken path, or broken script.

Has anyone any idea what's goning on here? My initial intention was to store 3 side of picture under the directory of one entity, according to the entity's id.


Now i feeling like having a problem to tell my team mate about my "idea"....

Please help, the most importantly, what's going on, any information is appreciated


<script language="javascript" type="text/javascript">
function mainwin(imgname, imgsrc)
document[imgname].src = imgsrc;
<img src="1/1.jpg" name="main_img" width="200px" height="150px" />

<input id="but" type="button" value="<" onclick="mainwin('main_img', 'ima/2.jpg');" />

10th April 2009, 06:57 PM
Hard to say without seeing your directory structure. My suggestion is use Firebug to troubleshoot the problem. You should be able to find what's going on quickly.

11th April 2009, 09:16 AM

My directory is simple

/test.htm (with the script)

These are working:

These are not working:

These are also not working, and I would like to know why

All of the above file stay in same directory, like /home/me/Desktop/test

I will check up with the Firebug and thx for the suggestion

12th April 2009, 06:04 PM
I am so sorry, I am dumb ***, the files in my other directories are having *.Jpg extension instead of *.jpg, but I only figure this out after putting them into my apache , as it remove previous picture and replace with an empty picture, unlike when I just open the htm file with firefox where the original picture was not affected at all. Makes me suspect Javascript will only work with certain file path ...