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 4 of 4
  1. #1
    BDT
    BDT is offline
    New Coder
    Join Date
    Mar 2003
    Location
    TX
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    if(doc.images[0]==doc.images[i]) ???

    I am trying to use document.images[] to compare images to see if they are the same as follows:


    for (i=1;i<=3;i++) {
    if(document.images[0].src==document.images[i])


    This isn't working and when I test it with:

    alert("Image[0]= " + document.images[0].src + " and image " + i + " = " + document.images[i])


    the test returns the proper image file name for what ever is on the left side of the conditional expression (==), but won't return the file of the image to the right. It just says that it is an [object].

    I suppose that I could use some string functions like:


    IMG= document.images[0].src;
    IMGi= document.images[i].src;
    (IMG.substring(0) if(IMG!=IMGi)


    But I'm thinkin' there's a better way. Any suggestions??

    thanks, BDT

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Montreal, Canada
    Posts
    644
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if(document.images[0].src==document.images[i])


    You only put src on one side. Maybe thats your prob.

  • #3
    BDT
    BDT is offline
    New Coder
    Join Date
    Mar 2003
    Location
    TX
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Doh!!! How can I look at something for so long and still not see it? I knew it would be simple, but didnt' think it would be THAT simple.

    thanks

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Montreal, Canada
    Posts
    644
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Expect it to happen again. The more you look at a script the more it merges together. I've done things like that all the time.


  •  

    Posting Permissions

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