471,350 Members | 1,410 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

Intermittent image load problem

Hi,

I have 3 small images on my page. I also have a large image which is
displayed when any of the 3 small images is clicked. I do this to display a
large version of each image. On page load the large image displays the img1
by default.

But sometimes (in IE and NS) when I click on small images, the large image
is empty and if I refresh the page it will display it. Here is my code:

function ChangeImage(Img)
{
document.getElementById("LargeImg").src =
document.getElementById(Img).src;
}

and on click event of each small image I have:

OnClick="ChangeImage('Img1')"
OnClick="ChangeImage('Img2')"
OnClick="ChangeImage('Img3')"
Why is this happening?
Thanks for your time
Regards
Mehdi
Jul 23 '05 #1
2 1936
On Sat, 21 Aug 2004 10:58:49 GMT, Mehdi <no****@nospam.nospam> wrote:
I have 3 small images on my page. I also have a large image which is
displayed when any of the 3 small images is clicked. I do this to
display a large version of each image. On page load the large image
displays the img1 by default.

But sometimes (in IE and NS) when I click on small images, the large
image is empty and if I refresh the page it will display it. Here is my
code:

function ChangeImage(Img)
{
document.getElementById("LargeImg").src =
document.getElementById(Img).src;
}

and on click event of each small image I have:

OnClick="ChangeImage('Img1')"
OnClick="ChangeImage('Img2')"
OnClick="ChangeImage('Img3')"


The code you've presented suggests that you aren't using small and large
images, but large images that have been shrunk using the height and width
attributes. If this is correct, the problem might be because the images
haven't finished loading. I couldn't really say without seeing the actual
page.

Of course, it could just be a bug. When I used IE, I noticed problems with
rollovers, but I think that it's because IE is so badly written, it wasn't
executing the correct code, or using the correct HTML[1].

What I will say though, is that it's preferable to access images using the
images collection, rather than getElementById().

function ChangeImage(img) {
document.images['LargeImg'].src = document.images[img].src;
}

Mike
[1] When I browse the Internet, I often use multiple windows (or tabs, now
I use Opera). IE seemed to confuse what data should go where and load
images from one page into another, or use images that should have been
located elsewhere on the page. I hate IE.

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2
Thanks Mike,

I'll try image collection.

Mehdi
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Lee Chapman | last post: by
3 posts views Thread by Velvet | last post: by
3 posts views Thread by helraizer1 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.