/    Sign up×
Community /Pin to ProfileBookmark

highlight menu

I would like to build a menu that highlight the active link

but my variable active_link is undefined after i click on the links i do use onclick=”active_link=n”

here is my attempt: Where do i am wrong?
<html>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME=”Author” CONTENT=””>
<META NAME=”Keywords” CONTENT=””>
<META NAME=”Description” CONTENT=””>
</HEAD>

<script language=”javascript”>
var active_link
</script>

<BODY onLoad=”active_link=0″>

<TABLE>
<TR>
<script language=”javascript”>

if(active_link==1){
document.write(“<TD><A HREF=’1.html’ onClick=’active_link=1;’ target=’main’><b>1</b></A></TD>”);
}else {
document.write(“<TD><A HREF=’1.html’ target=’main’ onclicK=’active_link=1;’>1</A></TD>”);
}

if(active_link==2){
document.write(“<TD><A HREF=’2.html’ target=’main’ onclicK=’active_link=2;’><b>2</b></A></TD>”);
}else {
document.write(“<TD><A HREF=’2.html’ target=’main’ onClick=’active_link=2;’>2</A></TD>”);
}

if(active_link==3){
document.write(“<TD><A HREF=’3.html’ target=’main’ onClick=’active_link=3;’><b>3</b></A></TD>”);
}else {
document.write(“<TD><A HREF=’3.html’ target=’main’ onClick=’active_link=3;’>3</A></TD>”);
}

</script>

</TR>
</TABLE>
<script language=”javascript”>
document.write(active_link);
</script>
</BODY>
</html>

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@VladdyJun 23.2004 — Menu is a LIST of links and you do not use javascript to write it.

In order to style the "link" to the current page differently replace anchor element with span:
&lt;ul&gt;
&lt;li&gt;&lt;a href="index.html"&gt;Home&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="page1.html"&gt;Page 1&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;span&gt;Current Page&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="page3.html"&gt;Page 3&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
×

Success!

Help @amrigo 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.25,
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,
)...