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
  1. #1
    Regular Coder
    Join Date
    Aug 2004
    Location
    The Netherlands
    Posts
    211
    Thanks
    0
    Thanked 1 Time in 1 Post

    id instead of name

    Hello. I'd like to make a valid XHTML site, but it uses a mouseover. Because of that I have to give some images the name atribute, but that isn't valid. The atribute id is, but it doesn't work with the javascript. This is my code:

    Code:
    <script type="text/javaScript">
    image1 = new Image();
    image1.src = "images/over2.gif";
    
    image2 = new Image();
    image2.src = "images/producten2.gif";
    
    image3 = new Image();
    image3.src = "images/bestellen2.gif";
    
    image4 = new Image();
    image4.src = "images/contact2.gif";
    
    <!-- the mouseover -->
    
    <a href="over.html" onmouseover="image1.src='images/over2.gif'" onmouseout="image1.src='images/over.gif'"><img name="image1" src="images/over.gif" width="96" height="44" alt="" /></a>
    </script>

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Then use document.getElementById('image1')

    Besides, the method you are using to call the image name is IE proprietary anyway. Thus it would not work for any other browser anyway....

    .....Willy

  • #3
    Regular Coder
    Join Date
    Aug 2004
    Location
    The Netherlands
    Posts
    211
    Thanks
    0
    Thanked 1 Time in 1 Post
    Oh... I got this code from some website because I have no javascript knowledge. Is there kind of code that supports all browsers?

    Thanks.

  • #4
    Regular Coder
    Join Date
    Aug 2002
    Location
    USA
    Posts
    625
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Besides, the method you are using to call the image name is IE proprietary anyway. Thus it would not work for any other browser anyway....
    Glenn says this too. What browsers does it not work in? In addition to IE, Mozilla Firefox also supports this syntax. It may be considered a quirk, but it does support it.



    -james
    Last edited by jamescover; 08-20-2004 at 05:59 PM.
    "God so loved the world that he gave his only begotten son, so that whosoever believed in him would not perish, but have everlasting life. For God did not send his son into the world to condemn the world, but so that through him the world might be saved. "

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Jero
    Oh... I got this code from some website because I have no javascript knowledge. Is there kind of code that supports all browsers?

    Thanks.
    Yes, there is. The images on a page are all loaded into a global array named "images" which can be referred to using either the index number (not a good idea) or by the ID. So another way to find the object for those images is:

    document.images["id of the image"]

    That said, the suggestion by Willy will work in all current browsers, only antiques like IE 4 and Netscape 4 don't recognize the getElementById function.
    Check out the Forum Search. It's the short path to getting great results from this forum.


  •  

    Posting Permissions

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