alicia1234
asked on
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.
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>
ASKER
It displays "Church Street Storagex" but not the "Return Policy" link ...
so what's wrong with my code? ;-)
so what's wrong with my code? ;-)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Duh.
You are exactly right. Above the code snippet I gave you, I had
Single "=" not "==" so I was actually setting the value of loc to "Church Street Storage" rather than testing for it.
Thank you!
You are exactly right. Above the code snippet I gave you, I had
if (loc="Church Street Storage") ...
Single "=" not "==" so I was actually setting the value of loc to "Church Street Storage" rather than testing for it.
Thank you!
I set loc = to another value and it stopped displaying the return policy Link.
save this as an html file and display it ...
Open in new window