How to conditionally display an element based on value of a URL parameter

I have javascript that successfully gets the value of a URL parameter "location" and makes it available to the page as "loc". Now, if the value of "loc" is "Church Street Storage", I want to display some stuff on the page, otherwise not.

In the code below, the first "document.write" accurately displays "Church Street Storage" so I know the correct value is in "loc". However, the if condition appears to be true all the time ... the "return policy" link displays regardless of the value of "loc".

Seems like this should be simple, but I don't know Javascript so I'm kind of winging it here.

<ul>
<script>document.write(loc);</script>
<script>
if (loc == 'Church Street Storage')
{document.write('<li><a href="/returnpolicy.shtml">Return Policy</a></li>');}
</script>
</ul>

Open in new window

alicia1234Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ken ButtersCommented:
your javascript seems to be accurate.

I set loc = to another value and it stopped displaying the return policy Link.

save this as an html file and display it ...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=windows-1250">
  <meta name="generator" content="PSPad editor, www.pspad.com">
  <title></title>
  </head>
  <body>
 <ul>
<script>
loc = 'Church Street Storagex'
document.write(loc);</script>
<script>
if (loc == 'Church Street Storage')
{document.write('<li><a href="/returnpolicy.shtml">Return Policy</a></li>');}
</script>
</ul>
  </body>
</html>

Open in new window

0
alicia1234Author Commented:
It displays "Church Street Storagex" but not the "Return Policy" link ...
so what's wrong with my code?  ;-)
0
Ken ButtersCommented:
that is my point... there is nothing wrong with your javascript.

Sounds to me like the issue must be the value of Loc.

I would say that the value of loc is not being set to anything other than "Church Street Storage" in your testing.

Do you have an example where you see something other than Church Street Storage displayed and yet still see the return policy link?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
alicia1234Author Commented:
Duh.
You are exactly right. Above the code snippet I gave you, I had

if (loc="Church Street Storage") ... 

Open in new window


Single "=" not "==" so I was actually setting the value of loc to "Church Street Storage" rather than testing for it.

Thank you!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.