Intermittent image load problem

Discussion in 'Javascript' started by Mehdi, Aug 21, 2004.

  1. Mehdi

    Mehdi Guest

    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
     
    Mehdi, Aug 21, 2004
    #1
    1. Advertising

  2. On Sat, 21 Aug 2004 10:58:49 GMT, Mehdi <> 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.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.
     
    Michael Winter, Aug 21, 2004
    #2
    1. Advertising

  3. Mehdi

    Mehdi Guest

    Thanks Mike,

    I'll try image collection.

    Mehdi
     
    Mehdi, Aug 21, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marina
    Replies:
    2
    Views:
    2,834
  2. pvl
    Replies:
    2
    Views:
    693
    Pierre-Andre van Leeuwen
    Mar 23, 2005
  3. Brano
    Replies:
    0
    Views:
    771
    Brano
    Jan 6, 2006
  4. Brano
    Replies:
    0
    Views:
    912
    Brano
    Jan 6, 2006
  5. Mark Szlazak
    Replies:
    3
    Views:
    196
    Fletch
    Apr 25, 2006
Loading...

Share This Page