Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JavaScript sub menu on mouse over

Status
Not open for further replies.

sn202

IS-IT--Management
Mar 24, 2005
6
GB
Hi all,

I'm trying to use JavaScript to display the sub-menu on mouse over using the following script:

<script type="text/javascript">
var sublinks = new Array();
// links for about section
sublinks[0] = new Array();
sublinks[0][0] = { href: 'about.htm', innerHTML: 'About the Senators | ' };
sublinks[0][1] = { href: 'about_perc.htm', innerHTML: 'About the Senators Percussion | ' };
sublinks[0][2] = { href: 'profiles.htm', innerHTML: '2005 Line Profile | ' };
// links for news section
sublinks[1] = new Array();
sublinks[1][0] = { href: 'news.htm', innerHTML: 'News | ' };
sublinks[1][1] = { href: 'news_archive', innerHTML: 'News archive | ' };
sublinks[1][2] = { href: 'latest_news.htm', innerHTML: 'Latest News | ' };
// links for Archive
sublinks[2] = new Array();
sublinks[2][0] = { href: 'archive.htm', innerHTML: 'Archive | ' };
sublinks[2][1] = { href: 'media.htm', innerHTML: 'Media | ' };
sublinks[2][2] = { href: 'shows.htm', innerHTML: 'Shows | ' };
sublinks[2][3] = { href: 'alumni.htm', innerHTML: 'Member Alumni | ' };
var n=0;
function displayLinks(n) {
var sub = document.getElementById('subLinks');
sub.innerHTML = '';
for (var i=0;i<sublinks[n].length;i++) {
sub.innerHTML += '<a href="'+ sublinks[n].href +'">'+ sublinks[n].innerHTML +'</a>';
sub.innerHTML += (i<(sublinks[n].length-1)) ? ' | ' : '';
}
}
</script>

I then have a div called "subLinks" and a div called "links" then use this format for each link on the menu:

<A href="about.htm" onmouseover="displayLinks(0)">

Basically its not doing anything at the moment, however when all the above is in the <head> it works correctly. Is there a way of getting round this and making it work correctly? Any help with this will be much appreciated.

Regards,

Simon.
 
Basically its not doing anything at the moment, however when all the above is in the <head> it works correctly. Is there a way of getting round this and making it work correctly?

If the code works correctly when it is the head section, then why not leave it there? Or do you need it out of the head section for some reason?

Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]

 
Well,

I'd rather have the "Links" and "SubLinks" Div and the <A href="about.htm" onmouseover="displayLinks(0)"> section in the body tag for layout and consistency purposes.

Any ideas?

Simon.
 

What happens if you put your script in the head section, and the html in the body section?

Dan



[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]

 
Well that's how I've got it at the moment, the JS is in the head section and the html in the body and its not doing anything. I don't know why this is, as I don't have a great deal of experience with JS. Can you see any reason for this in the script?

Cheers,


Simon.
 

Are you saying that when you move your HTML code (subLinks div, a elements, etc) into the HEAD section that your menu displays and works correctly, but when you move your HTML code to the BODY, leaving your script in the HEAD, that it all goes pear-shaped?

Just so we can clarify when it does and does not work.

Dan



[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]

 

Can you post either a URL to you page, or the source menu source that is missing, please?

Dan



[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top