Click to See Complete Forum and Search --> : Javascript Problem


IzzieLeeLucas
11-20-2003, 11:24 AM
Hi,

I've written some basic javascript which, when an image thumbnail is clicked on, will open up a named child window of a specified size. Then, using getElementById, I changed the SRC in the IMG tag on the new window to specify an image to display. (I hope that makes sence)

As I have lots of image thumbnails on one page and different sized images I decided that rather than have a different Javascript Function for each image, I would specify the size and the image to diplay in the onClick of the thumbnail.

From the way I try to explain things, You may have no idea what I'm talkin about so heres the script (cut down slightly to save space)...

HTML File 1 (pictures.html) - Displays the thumbnails

<html>
<head>
<script language="JavaScript">
function open_window(mwidth,mheight){
picture = eval('window.open("image.html","","width='+mwidth+',height='+mheight+'")');
}

function load_image(location){
var pic = picture.document.getElementById("image");
pic.src = location;
}
</script>
</head>

<body>
<img onClick="open_window(340,558);load_image('pic1.jpg');" border="0" src="thumbpic1.jpg" width="60" height="100">
<br>
<img onClick="open_window(325,458);load_image('pic2.jpg');" border="0" src="thumbpic2.jpg" width="60" height="100">
</body>
</html>

HTML file 2 (image.html) - Contains the image

<html>
<head>
</head>
<body>
<img src="" id="image">
</body>
</html>

Now my problem is this... what I've written works perfecly fine when I run it from my computer harddrive, but when I upload it to my server, the child window will come up, but the image won't display. I just get a small box outline with the red X in it.

How come it will work on my computer but not on the server? I have other javascript running on it fine.

Thanks for any help,
Izzie

neil9999
11-20-2003, 11:36 AM
Have you uploaded the images to your server? Are they in the same folder?

You also may want to use this script I invented. To see it go to http://www.codingforums.com/showthread.php?s=&threadid=27843

Neil

IzzieLeeLucas
11-20-2003, 12:23 PM
Yeah all the pics are uploaded and in the right folder.

Thats a pretty good photoablum, but the design of my site prevents me from using it :(

: [Izzie] :

TheBearMay
11-20-2003, 02:05 PM
Izzie still sounds like a image path problem, is there a site we can look at real quick?

IzzieLeeLucas
11-20-2003, 02:34 PM
yeah, http://izzieleelucas.netfirms.com/photogallery/city270903/folder/test.htm

Thats just a cut cown version with only 2 pics in it. And as you may guess, my server is NetFirms.

I seem to have developed an error, on the line that says pic.src = location; and I have no idea why, I may have been there before, but again, that doesn't apear when I run it from my computer.

Thanks for you help.

Izzie

TheBearMay
11-20-2003, 03:08 PM
Okay looking at the properties for the photo in the new window the file name is set to:

http://izzieleelucas.netfirms.com/photogallery/city270903/folder/

(note no picture name);

The line:
var pic = picture.document.getElementById("image");
is returning null, and the src property does not exist for null.

IzzieLeeLucas
11-20-2003, 03:37 PM
I've just realized that once the file has beed uploaded to the server, all the banner ads get stuck at the top of the page... so line 10 isn't my script, its theirs... right? Either way it seems to have dissapered now.

But why wont the SRC of the image change to the one specified in the onClick on the thumbnail! I can't understand why the script will work on my computer but not on the server, even tho the files are exactly the same... apart from the added banner scripts (I wonder if this could be the problem :confused: )

I gonna have to work on a new one thats gonna work on the server. hopefully!

Cheers
Izzie