linking a javascript document to HTML page.?

They have: 7 posts

Joined: May 2006

Sorry I am very new to javascript, I have written my site in HTML and CSS but I have created a drop down menu which links to about 30 pages within my site. Originally it was only available on the homepage but I would like to have it at the top of every page.

Problem is, when I add new pages to my site I dont want to update EVERY drop down box on every page? Is there an easy way of doing this please.? I assume I can create a javascript file seperate file and link it to my pages so that every time I update the drop down box on the main file it automatically updates on every page, I just have no idea ow I do this or where I would need to place the javascript within the HEAD and BODY of each page so that it displays the updated version each time;

This is the code I have used to create the drop down menu;

Select

W
X

and I think this goes into the body section where I want the box to appear
Select<script language="javascript" type="text/javascript">document.write(dropdown)</script>

Thanks in advance

teammatt3's picture

He has: 2,102 posts

Joined: Sep 2003

EDIT: I just realized you have to put something in the head. So ignore the below post.

You might want to switch all the extensions on your site from htm or html, to PHP (if it is enabled by your server) and then you can use a simple PHP include.

First create a file called navigation.php with just the javascript in it (no etc) then, on each of your pages that you want to see the menu, put this at the top, right after

<?php
include ('navigation.php');
?>
and that will include navigation on the top of the page. Anytime you add a page, just change navigation.php and it will work.

I think there is a way to do it in js, but I don't know how.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.