Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Image Swapping

  1. #1
    New to the CF scene
    Join Date
    Feb 2007
    Location
    Bristol
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Image Swapping

    I have the following code to swap an image when a thumbnail is clicked:

    Code:
    <img id="ctl00_main_content_dlImages_ctl02_imgPic" class="csspointer" onclick="var button1_up = new Image(); button1_up.src = 'datastore/images/lrge_37disabled.jpg';document.largeimage.src = button1_up.src;" src="datastore/images/thmb_37disabled.jpg" alt="disabled.jpg" style="border-width:0px;" />
    Which swaps:

    Code:
    <img src="http://www.youcanpark.com/datastore/images/lrge_37IMG_1122.JPG " id="largeimage"/>
    It works fine in Firefox, but IE and Opera will not swap the image. Does anyone have any suggestions as to how I might correct this?

    Thanks

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    Code:
    document.largeimage
    is not the advisable way to access the image especially when u have an id attached to it

    use
    Code:
    document.getElementById('largeimage')
    but, if u don't care for such things adding a name attribute to the image will do the trick too
    Code:
    <img src="http://www.youcanpark.com/datastore/images/lrge_37IMG_1122.JPG " id="largeimage" name="largeimage"/>

  • #3
    New to the CF scene
    Join Date
    Feb 2007
    Location
    Bristol
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I actually came to the same conclusion shortly after posting, works a treat. Many thanks for the quick advice Shyam.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •