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 5 of 5

Thread: Array objects

  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Posts
    672
    Thanks
    1
    Thanked 1 Time in 1 Post

    Array objects

    I have a page with a mix of images that I don't want indexed. It is a 5x5 grid, each being an image (but the border edges are counted too unfortunately.). So I assign names to the images instead. That is a very space consuming thing to do. So now I try to put all the names into an array to reduce recurring names throughout the file like this:
    N[1]=document.images.M[0].src //(assume some values)

    When I try to set variables form arrays, I get many errors like "object expected" and "undefined". Is there a way to fix this?

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok, "document.images.M[0].src" is invalid. My question for you is, what is 'M'? You you have images named M0, M1, M2, M3, etc?
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #3
    Regular Coder
    Join Date
    Nov 2002
    Posts
    672
    Thanks
    1
    Thanked 1 Time in 1 Post
    Lets say I have

    M=Array("A1","A2","A3","A4","A5","B1") // all the way up to E5
    N=Array() //blank array for adding on to

    Then I have images in a grid each with a name.

    <img src="2p0.gif" name="A1" />

    and I want to dynamically change the images at certain events in a shifting way.

    document.images.A1.src=document.images.E5.src

    I could write 25 lines of that. But I wanted to simplify it into a for loop.

    for (i=0; i<25; i++)
    {
    document.images.M[i].src=N[i+1] //building a new array
    }

    It's the M[] part that is being taken literal.

  • #4
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oh, you need

    document.images(M[i]).src
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #5
    Regular Coder
    Join Date
    Nov 2002
    Posts
    672
    Thanks
    1
    Thanked 1 Time in 1 Post

    Thumbs up

    Ah I knew it had to be something simple like that. Thanks!


  •  

    Posting Permissions

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