/    Sign up×
Community /Pin to ProfileBookmark

Changing text color or css style

hello all, I hope I can get help here. I am newbie in java script and I am trying to do the following:
I have a navigation bar on my website (made of link text, the color of the text is defined by a css style, in any case the text is white when the page loads and is red when it gets rolled over) What I want is when a vistor for example presses the “machine” button and gets directed to the page “machine.asp” which displays the same navigaton, I want the text for the link “machine” on my navigation to change to red for example and stay that way, that way the visitor will know what page s/he is on.
structure of website:
Each page (home.asp, machine.asp, ingredients.asp, etc.) includes a header called (head.asp) and a footer (foot.asp)
[URL]http://www.always-coffee.com/web2/index.asp[/URL]

What I did:
I added the following javascript in head.asp:

<!– Original: Kevin Lynn Brown Modefied by Layth–>

<!– Begin
var path = “”;
var nav = “”;

var href = document.location.href;
var s = href.split(“/”);
for (var i=2;i<(s.length-1);i++) {
}
i=s.length-1;
path+=s[i];

if (path == “always-coffee-office-solution_main.asp”){

nav=”main”;

var nav =””;
}

// End –>

Now here is my problems (or what I think My problems is):

2- now if I get the first part right, then I can add more if statments to include all websites for the navigation part. BUT my biggest problem, is how do I get the text change color if the value of the variable nav=”main” for example. AND where do I place that code in my document. PLEASE HELP. and I thank you in advance.
Layth

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@CharlesOct 30.2004 — [font=monospace]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"

"http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<meta name="Content-Script-Type" content="text/javascript">

<meta name="Content-Style-Type" content="text/css">

<title>Example</title>

<style type="text/css">

<!--

a.current {background-color:#a00; color:#fff}

-->

</style>

<script type="text/javascript">

<!--

onload = function () {

var l, i = 0;

while (l = document.links[i++]) {if (l.href == location) l.className = 'current'}

}

// -->

</script>

</head>

<body>

<ul>

<li><a href="test.html">Test</a></li>

<li><a href="http://www.w3.org/">W3C</a></li>

</ul>

</body>

</html>[/font]
Copy linkTweet thisAlerts:
@laythssauthorOct 31.2004 — I am not sure how that code works but I tried it out and it works as the example but how do I add it to my links at my nav, my code right now for these buttons is:

<table cellpadding="0" cellspacing="0" border="0" width="1020">

<tr bgcolor="#66CC00">

<td width="196" align="center" bgcolor="#66CC00" class="backnavgray"><span class="nav"><a href="index.asp" class="style4" onMouseOver="this.className='navon';" onMouseOut="this.className='nav';">Home</a></span></td>

<td width="54" align="center" bgcolor="#FFFFFF" class="backnavgray"><div align="center"><span class="nav"><a href="always_coffee_office_machine.asp" class="nav style7" onMouseOver="this.className='navon';" onMouseOut="this.className='nav';">Machine</a></span>

</div></td>

<td width="73" align="center" bgcolor="#FFFFFF" class="backnavgray"><div align="center"><span class="nav"><a href="always_coffee_office_machine_espresso_coffee_ingredients.asp" class="style4" onMouseOver="this.className='navon';" onMouseOut="this.className='nav';">Ingredients</a></span></div></td>

<td width="64" align="center" bgcolor="#FFFFFF" class="backnavgray"><div align="center"><span class="nav"><a href="always_coffee_office_machine_selections.asp" class="style4" onMouseOver="this.className='navon'" onMouseOut="this.className='nav'">Selections</a></span></div></td>

<td width="111" align="center" bgcolor="#FFFFFF" class="backnavgray"><div align="center"><span class="nav"><a href="always_coffee_office_solution_coins_dollars_free_payment.asp" class="style4" onMouseOver="this.className='navon';" onMouseOut="this.className='nav';">Payment<span class="style5">_</span>Options</a></span></div></td>

<td width="74" align="center" bgcolor="#FFFFFF" class="backnavgray"><div align="center"><span class="nav"><a href="always_coffee_office_solution_service.asp" class="style4" onMouseOver="this.className='navon';" onMouseOut="this.className='nav';">Our<span class="style5">_
</span>Service</a></span></div></td>

<td width="47" align="center" bgcolor="#FFFFFF" class="backnavgray"><div align="center"><span class="nav"><a href="always_coffee_office_machines_contact.asp" class="style4" onMouseOver="this.className='navon';" onMouseOut="this.className='nav';">Contact</a></span></div></td>

<td width="68" align="center" bgcolor="#FFFFFF" class="backnavgray"><div align="center"><span class="nav"><a href="always_coffee_office_emergencycontact2.asp" class="style4" onMouseOver="this.className='navon';" onMouseOut="this.className='nav';">Emergency</a></span></div></td>

<td width="29" align="center" bgcolor="#FFFFFF" class="backnavgray"><div align="center"><span class="nav"><a href="always_coffee_office_machines_jobs.asp" class="style4" onMouseOver="this.className='navon';" onMouseOut="this.className='nav';">Jobs</a></span></div></td>

<td width="38" align="center" bgcolor="#FFFFFF" class="backnavgray"><div align="center"><a href="always_coffee_office_machine_aboutus.asp" class="style4" onMouseOver="this.className='navon'" onMouseOut="this.className='nav'">About</a></div></td>

<td width="40" align="center" bgcolor="#FFFFFF" class="backnavgray">&nbsp;</td>

</tr></table>

At least can some one just right for me how the code in the past post actually work. Many thanks for any help.

Layth
Copy linkTweet thisAlerts:
@CharlesOct 31.2004 — You mkght be able to wrestle that thing into cooperating but you would do best to get rid ofthe table, use CSS for layout and presentation and go with HTML 4.01 Strict. You'll at least have to use CSS for the presentation for my method to work.
×

Success!

Help @laythss spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...