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

need a clever way to change a button based on where the user is

Status
Not open for further replies.

fpl9250

Programmer
Jan 22, 2007
46
US
Hello,

I have a page that has a 4 button menu at the top included via SSI. They want the text on the button to change color when the respective page for each button is active. I can't hard code a different button for each page. This is a site of 100s of pages and they menu is via SSI, and the styles are applied globally.

What can I do here? Maybe some kind of js that can be on every page, that recognizes where it is, and based on that changes the button A for button A2 or something.

Help?
 
Hi

Yes, exactly.

If you give use details, post some code, post an URL to that page ( or all three ), we could help with a proper solution too.

If we would not be in the JavaScript forum I would say 4 buttons are not many to code their coloring in the included file.

Feherke.
 
I use the following method.

Create a css class for 'selected' items.
Apply an id to the body of each page.
Apply an id to each nav element, make it similar to it's corresponding page. e.g. page body id is 'contact' so the nav element for that page is 'nav_contact'.
Use some javascript to read the id of the body tag on the page do a bit of string comparison and apply the selected class to the appropriate nav element.


Something like this...

Code:
if(!document.getElementById('subNav')) return false;
	var thisPageId = document.body.getAttribute('id');
	var targetId = 'nav_' + thisPageId;
	if(!document.getElementById(targetId)) return false;
	document.getElementById(targetId).className='selected';

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top