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 6 of 6
  1. #1
    New Coder
    Join Date
    Oct 2003
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    creating a variable for document.images

    I would like to use an all-encompassing script for several elements of the page I am working on. In order to do this I need to put a variable in document.images. I've tried:

    var thisimg;

    document.images["thisimg"].src;
    document.images[thisimg].src;
    document.images["'thisimg'"].src;
    document.images.thisimg.src;

    none of those seems to work...thanks in advance for any help!
    Help! I've reached the end of my code!

  • #2
    Regular Coder
    Join Date
    Jul 2003
    Location
    Massachusetts
    Posts
    472
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What exactly are you trying to do? If it's accessing the src attribute of an image, what you have there should suffice (1, 3, and 4 anyway; 2 won't work because thisimg doesn't have anything assigned to it) assuming the names are correct. A quick guess would be that this code isn't being executed via the window.onload event handler, hence, the image objects do not yet exist and you therefore cannot access them.

  • #3
    New Coder
    Join Date
    Oct 2003
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    not quite...what I'm doing is trying to use the same code for an image swap of three different images. Ex. Image 1 from a hamburger to a hot dog, image 2 from a car to a truck, and image 3 from a basketball to a baseball. I have buttons under each image that control the swap. What's not working is I need to establish a variable that can be manipulated for the document.images['this variable here'].src for the 3 images. In other words, I'm trying to use the same code to access the .src for three different images. If that doesn't make sense to anyone, I'll copy the code here so you can see exactly what I'm trying to do.
    Last edited by xupaosso; 06-07-2004 at 05:08 AM.
    Help! I've reached the end of my code!

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,968
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Something like this?

  • #5
    New Coder
    Join Date
    Oct 2003
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Perfect!! I looked through the forums before and couldn't find it! Thanks, glengv!
    Help! I've reached the end of my code!

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,968
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Sometimes, you just have to use the right keywords to get more results.


  •  

    Posting Permissions

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