/    Sign up×
Community /Pin to ProfileBookmark

Simple Javascript Not Working

I am posting my question again because I believe the title was a little misleading. What is wrong with this code?? I use it so determine if you are filtering by a certain type Javascript replaces the link to the filter with bold text. For example: when you are filtering, the address of my site contains /search/label/(tag). So, if you were filtering by How-To’s the address would be /search/label/how-to. When Javascript checks document.location.href.index.Of(“/search/label/how-to”) == -1 it evaluates false (Since it is there). So instead of displaying a link to filter by How-To’s, Javascript makes the Text: How-To’s bold to indicate it is the current filter. I have tried using many online validators, but I have had no luck. Please Help! Here is my code:

[CODE]
if (window.location.href.indexOf(“/search/label/articles”) == -1)
{
document.write(“<li><a href=’/search/label/articles’>Articles (4)</a></li>”);
}
else
{
document.write(“<li><b>Articles (4)</b></li>”);
}
if (window.location.href.indexOf(“/search/label/how-to”) == -1)
{
document.write(“<li><a href=’/search/label/how-to’>How-To’s (2)</a></li>”);
}
else
{
document.write(“<li><b>How-To’s (2)</b></li>”);
}
if (window.location.href.indexOf(“/search/label/tip”) == -1)
{
document.write(“<li><a href=’/search/label/tip’>Tips (2)</a></li>”);
}
else
{
document.write(“<li><b>Tips (2)</b></li>”);
}
if (window.location.href.indexOf(“/search/label/tutorial”) == -1)
{
document.write(“<li><a href=’/search/label/tutorial’>Tutorials (1)</a></li>”);
}
else
{
document.write(“<li><b>Tutorials (1)</b></li>”);
}
[/CODE]

Thanks!!!

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@bialeckiJun 29.2008 — Have you tried putting some alerts in your code to figure out what the flow of the logic is that you're seeing? As this code is written now, it looks like it might work, but is inefficient in a number of ways. Let's start by getting it to work and then we can clean it up so it's more conside.

I would start by putting alerting what the value of window.location.href is. Post what you think it should be and what it is actually set to.
×

Success!

Help @webcoder13 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 6.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...