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
    New to the CF scene
    Join Date
    Mar 2003
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Changing links onMouseOver and/or anchors array problem

    I'm having a problem with the Javascript navigation on a web page I'm attempting to build, and was hoping someone here would have some ideas how to fix it before I have to scrap my design.

    I had gotten the bright idea to have as navigation rollovers that loaded not only several new graphics, but also changed the links on those graphics. And when you roll over another navigation graphic, the destination graphics and links change yet again. I had no problem implementing the changes to the graphics, but learned that I couldn't use link names to change the link destination in Javascript, and had to change them according to their numbers instead. Unfortunately, the navigation appears after the content, so just about every page has the navigation links in a different position.

    Because most of the pages are going to be dynamically generated from a content management system (MovableType), I was hoping to have the navigation dynamically generated also so I wouldn't have to update all the Javascript rollovers each time I added a link to the page. To that end, I tried making a little Javascript utilizing the anchors array to count the number of links currently on each page so I could figure out the position of the navigation links from that, but for some strange reason the Javascript only returns a count of 5, even if there are dozens of links on the page.

    So, if anyone has any ideas as to why said Javascript isn't returning the correct number of links, or if anyone has any ideas as to how I can make the navigation work without much pain, please let me know what I'm doing wrong. I'd really rather not have to start all over again at this point! The page in question is currently in a state of disrepair at:
    http://weddingmusic.retrofit.net

    Thanks in advance,
    Michelle

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Can you narrow this down a bit - show us which piece of code you're concerned with, what it returns, and what you want it to return.
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #3
    New to the CF scene
    Join Date
    Mar 2003
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    more on the problem

    Here's the code I'm using to try and get the number of links on each page:

    var linksCount = document.anchors.length;
    document.write(linksCount);
    For some reason it always returns a value of 5, no matter how many links there are. I'd like it to return the actual number of links so that I can use that number to dynamically change the first value after "yaHrefChange" below:

    <a href="readings.php" onMouseOver="yaHrefChange('2','quotes.php'); yaHrefChange('4','biblical.php'); yaHrefChange('6','poetry.php'); yaHrefChange('8','prose.php'); yaHrefChange('10','specialty.php'); imageA.src='images/quotes.jpg'; imageB.src='images/biblical.jpg'; imageC.src='images/poetry.jpg'; imageD.src='images/prose.jpg'; imageE.src='images/specialty.jpg'; return true;"><img src="images/readings.jpg" name="image1" width=113 height=24 border=0 alt=""></a>
    The above is an example of the code I'm using to change both images and their destination links in the navigation; I was able to change the images onmouseover by naming them, but the hrefs can only be changed by using their number on each page. That's why I needed an easy way of getting the total number of links on the page.

    Thanks again for any advice you can provide. It's probably something very simple that I'm missing!

  • #4
    Regular Coder
    Join Date
    Jul 2002
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts
    anchors ain't links.

    they are places defined in ur document that u can get ur document to jump to with for instance links.


    if u want a link to be counted in the anchor collection u simply gives it a name/id

    <a name="test"></a>

    the reason it returned anything but o is that u got these in ur codes
    <a name="000480"></a>

    and u jump to a anchor by such a link as this.
    <a href="#000478">TEst</a>


    what you wanted is the numbers of links that u get by
    document.links.length;

  • #5
    New to the CF scene
    Join Date
    Mar 2003
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    whew

    I knew it had to be something simple. Thanks for pointing out the difference, Garadon.


  •  

    Posting Permissions

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