SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    Former Staff Member silver trophy Adam P.'s Avatar
    Join Date
    Apr 2001
    Location
    San Francisco
    Posts
    3,288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Back again w/ a validation problem: javascript rollovers and "name" attribute

    Hi. I'm using this code for some JS rollovers:

    Code:
    <a href="contact.php" onmouseover="changeImages('contact', 'contact_over')" onmouseout="changeImages('contact', 'contact')">
    <img src="images/contact.gif" width="70" height="27" border="0" alt="Contact" name="contact"></a>
    Of course there is the script too, but it doesn't really matter for this.

    Anyways, the code in bold coresponds to the "name" attribute in the image. But according to W3C:

    "Error: there is no attribute "NAME" for this element (in this HTML version)".

    How can I make the script still work without the "name" attribute?

    The site is here: http://www.help4newbies.com/AA

    Thanks!
    Last edited by Adam P.; Jul 3, 2002 at 19:37.
    SPF Mentor/Advisor 2001-2003
    SPF Designer of the Year 2002
    SPF Graphic Designer of the Year 2003
    AdamPolselli.com

  2. #2
    + platinum's Avatar
    Join Date
    Jun 2001
    Location
    Adelaide, Australia
    Posts
    6,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Would it have anything to do with the space after before the tag finishes?

    Code:
    name="compliance" ></a></td>
                     ^

  3. #3
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I believe you're supposed to be using the id attribute instead of name.
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  4. #4
    Former Staff Member silver trophy Adam P.'s Avatar
    Join Date
    Apr 2001
    Location
    San Francisco
    Posts
    3,288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by platinum
    Would it have anything to do with the space after before the tag finishes?

    Code:
    name="compliance" ></a></td>
                     ^
    Nope - that was just a typo.
    SPF Mentor/Advisor 2001-2003
    SPF Designer of the Year 2002
    SPF Graphic Designer of the Year 2003
    AdamPolselli.com

  5. #5
    Former Staff Member silver trophy Adam P.'s Avatar
    Join Date
    Apr 2001
    Location
    San Francisco
    Posts
    3,288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by creole
    I believe you're supposed to be using the id attribute instead of name.
    Tried it - rollovers don't work with "id".
    SPF Mentor/Advisor 2001-2003
    SPF Designer of the Year 2002
    SPF Graphic Designer of the Year 2003
    AdamPolselli.com

  6. #6
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To be perfectly honest, I wouldn't really worry about it. If that's the only part of your page that's not compliant then you're in better shape than any of my sites.
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  7. #7
    SitePoint Member
    Join Date
    Apr 2002
    Location
    New Zealand
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Wink similar problem, solved

    I had a similar problem, see this thread in the javascript forum:

    http://www.sitepointforums.com/showt...threadid=67699

  8. #8
    Grumpy Mole Man Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,066
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Rollovers should work fine with ID, but you'll probably have to alter your changeImages() function. Post the code here so we can have a look.

  9. #9
    Former Staff Member silver trophy Adam P.'s Avatar
    Join Date
    Apr 2001
    Location
    San Francisco
    Posts
    3,288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's the JS:
    Code:
    if (document.images) {
      about = new Image();
      about.src = "images/about.gif";
      about_over = new Image();
      about_over.src = "images/about_over.gif";
    
      compliance = new Image();
      compliance.src = "images/compliance.gif";
      compliance_over = new Image();
      compliance_over.src = "images/compliance_over.gif";
    
      etc.
    }
    
    function changeImages() {
      if (document.images) {
        for (var i=0; i<changeImages.arguments.length; i+=2) {
          document[changeImages.arguments[i]].src = eval(changeImages.arguments[i+1] + ".src");
        }
      }
    }
    And here's what the links look like:

    Code:
    <a href="compliance.php" onmouseover="changeImages('compliance', 'compliance_over')" onmouseout="changeImages('compliance', 'compliance')">

    Thanks for the link Bekks, but I didn't really understand what I needed to do.
    SPF Mentor/Advisor 2001-2003
    SPF Designer of the Year 2002
    SPF Graphic Designer of the Year 2003
    AdamPolselli.com

  10. #10
    Former Staff Member silver trophy Adam P.'s Avatar
    Join Date
    Apr 2001
    Location
    San Francisco
    Posts
    3,288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone?
    SPF Mentor/Advisor 2001-2003
    SPF Designer of the Year 2002
    SPF Graphic Designer of the Year 2003
    AdamPolselli.com

  11. #11
    Grumpy Mole Man Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,066
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:
    Code:
    <img src="image.gif" id="MyImage">
    Then some javascript somewhere that says...
    Code:
    document.getElementByID('MyImage').src = 'otherimage.gif';

  12. #12
    Former Staff Member silver trophy Adam P.'s Avatar
    Join Date
    Apr 2001
    Location
    San Francisco
    Posts
    3,288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Skunk
    Then some javascript somewhere that says...
    Code:
    document.getElementByID('MyImage').src = 'otherimage.gif';
    Please pardon my lack of javascript knowledge, but where exactly does this go?
    SPF Mentor/Advisor 2001-2003
    SPF Designer of the Year 2002
    SPF Graphic Designer of the Year 2003
    AdamPolselli.com

  13. #13
    Grumpy Mole Man Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,066
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could drop it in the onmouseover attribute or a function. Alternatively, just use mattjacob's standards compliant rollover script mentioned in this thread: http://www.sitepointforums.com/showt...threadid=68053

  14. #14
    Former Staff Member silver trophy Adam P.'s Avatar
    Join Date
    Apr 2001
    Location
    San Francisco
    Posts
    3,288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Skunk
    You could drop it in the onmouseover attribute or a function. Alternatively, just use mattjacob's standards compliant rollover script mentioned in this thread: http://www.sitepointforums.com/showt...threadid=68053
    mattjacob's script still uses the name attribute in the img tag to make the script work - that's what I'm trying to get away from. But it's a much shorter and easier to implement script - I'll use it in the future.
    SPF Mentor/Advisor 2001-2003
    SPF Designer of the Year 2002
    SPF Graphic Designer of the Year 2003
    AdamPolselli.com

  15. #15
    SitePoint Wizard
    Join Date
    Oct 2001
    Location
    Tucson, Arizona
    Posts
    1,858
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by swimm5001
    mattjacob's script still uses the name attribute in the img tag to make the script work - that's what I'm trying to get away from.
    I can't argue that, but maybe I'll make one using the ID attribute in the future.


Bookmarks

Posting Permissions

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