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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

creating an external JS file? Possable?

Status
Not open for further replies.

WannaLearn

Programmer
Jul 10, 2001
210
US
Hi, I have a side-menu that i'm working on and so far its great, in fact I have no problem with the menu itself, I had a problem earlier but someone in this forum (I believe it was valeriav) helped me out. :)
But now i'm faced with another issue.
Is it somehow possable to have the menu links (which are called as <div>s) as an external .js file? I mean, the area where the side-menu has the <href> tags. Becuase the side-menu will be on a number of pages, and if the menu links has to be changed then all the pages have to be changed, you can see the problem there. If the menu is on 10 pages then all those have to be changed if the side-menu changes.
I've uploaded a sample file here: Anyone have an idea?
 
It is possible to create a menuItems.js file to hold the menu items in a set of arrays for each menu item, for example. This file should be included in the header section of your page. You will then have to use javascript and document.writes to loop through the arrays and write the html that is necessary for the menu divs. Check out this example for a really good sliding menu:


Looking at the code will provide a great tutorial for how to accomplish this kind of thing. The menu system is different, but the general principles are the same.

By the way, it appears that your code doesn't work in Netscape 4.x browsers (which may be acceptable in your situation). If you don't need to support these 'downlevel' browsers, you can avoid using document.write by using the DOM (Document Object Model) and its related methods of manipulating and creating html elements.

Good Luck!
:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top