...

View Full Version : Changing links onMouseOver and/or anchors array problem



BlueRose
06-08-2003, 05:57 AM
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!:rolleyes: The page in question is currently in a state of disrepair at:
http://weddingmusic.retrofit.net

Thanks in advance,
Michelle

brothercake
06-09-2003, 12:36 PM
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.

BlueRose
06-10-2003, 10:30 PM
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!

Garadon
06-10-2003, 11:14 PM
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;

BlueRose
06-11-2003, 06:45 AM
I knew it had to be something simple. Thanks for pointing out the difference, Garadon.:)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum