PDA

View Full Version : javascript roll over funny phenomenon


meowdin
9th April 2009, 11:19 AM
Hi,

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.

Like
/1/1.jpg
/1/2.jpg
/1/3.jpg
/2/1.jpg
...etc

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


<html>
<head>

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

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

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

meowdin
11th April 2009, 09:16 AM
Hi,

My directory is simple

/test.htm (with the script)

These are working:
/img/1.jpg
/img/2.jpg

These are not working:
/1/1.jpg
/2/2.jpg

These are also not working, and I would like to know why
/img/1/1.jpg
/img/1/2.jpg
/img/2/1.jpg

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

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

Sandikli Photos - Kolkata - Montevarchi Instagram Photos