Hello,
I want to use Images as menu and menu items using javascript.The aim is that i have images with the menu items. when i click the image on that perticular mmenu item i want an image to be loaded there with that menu item highlighted.
Suppose the menu has
Home,Products,Contact us
The image has these items.
When the user clicks Home , i want the Image with Home highlighted to be loaded. when the user clicks Contact Us, The image with Contact Us highlighted to be loade.
Since this is a single image how can i detect what Menu Item or option is clicked by the user?
Please let me know asap
Hi,
-
test_image = new Image();
-
function getLeaf(url)
-
{
-
return url.substring(url.lastIndexOf("/")+1);
-
}
-
function highlightCurrentMenuItem()
-
{
-
var currentLocation = getLeaf(document.location.href);
-
var menu = document.getElementById("menu");
-
links = menu.getElementsByTagName("a");
-
for (i=0; i<links.length; i++)
-
{
-
var currentHref = links[i].getAttribute("href");
-
var currentLeafName = getLeaf(currentHref);
-
if (currentLeafName==currentLocation)
-
{
-
document.test_image.src = "images/globe.gif";
-
}
-
}
-
}
-
In every page use
[HTML]<body onload="javascript
:highlightCurrentMenuItem();">[/HTML]
In other pages do like this;
In home page
[HTML]<li><a href="index.html" title="">
<img name="test_image" id="test_image" src="images/color_spacer.gif" align="top" />Home</a></li>
<li><a href="" title="">About Us</a></li>
<li><a href="" title="">Services</a></li>
<li><a href="" title="">Portofolio</a></li>
<li><a href="contact.html" title="">Contact</a></li>[/HTML]
In contact_us page
[HTML]<li><a href="index.html" title="">Home</a></li>
<li><a href="" title="">About Us</a></li>
<li><a href="" title="">Services</a></li>
<li><a href="" title="">Portofolio</a></li>
<li><a href="contact.html" title="">
<img name="test_image" id="test_image" src="images/color_spacer.gif" align="top" />Contact</a></li>[/HTML]
SO ON.....
Happy Programming!
:)