Small ASP question

Zucarita9000

Golden Member
Aug 24, 2001
1,590
0
0
Ok, so I have this navigation bar wich should show the links from a given section only when the user is browsing that specific portion of the site. Example:

The nav bar shows items like this:

Section 1
Link 1.1
Link 1.2
Link 1.3

Section 2
Link 2.1
Link 2.2
...
Etc.

So, when the user is browsing section 1, the navbar should only display the links from that section, hiding all the items from section 2:

User location: www.site.com/section1/
Nav bar:

Section 1
Link 1.1
Link 1.2
Link 1.3

Section 2
Section 3
...
Section 5

I've come up with this idea: Check the URL and display the correct items, like this:

<% If Request.ServerVariables("URL") ="/section1/" Then %>
Link 1.1
Link 1.2
Link 1.3
<% End If %>

This should show the correct itwems whenever the user is browsing the "section1" directory. However, it's not working at all.

Any ideas?
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
Originally posted by: Zucarita9000
Originally posted by: AFB
Print out the URL and see what it *is* equal to.

Not sure I follow... isn't that what I'm doing?

<% If Request.ServerVariables("URL") ="/section1/" Then %>


You're comparing it and I guess it's not working.

Print out the value of URL so you can see why it's not cimplaring correctly.
 

brentman

Senior member
Dec 4, 2002
628
0
0
you are printing the links no matter what the result of the conditional is....

<% If Request.ServerVariables("URL") ="/section1/" Then %>
Link 1.1
Link 1.2
Link 1.3
<% End If %>


needs to be like this...

<% If Request.ServerVariables("URL") ="/section1/" Then
response.write("Link 1.1 ")
response.write("Link 1.2 ")
response.write("Link 1.3 ")
End If %>

EDIT:

You may also want to consider using InStr() as I am not sure what the URL variable contains. It might be the full URL not just the end section. It may be fouling up your conditional results.

<% if InStr(request.servervariables("URL"),"section1") then

that sort of thing.

 

torpid

Lifer
Sep 14, 2003
11,631
11
76
Couple possibilities:

1. URL might have a page name after the /. You can try instr or you can do a left of the URL.

2. Might have case sensitivity issues. Do an LCASE of the URL before comparing.
 

torpid

Lifer
Sep 14, 2003
11,631
11
76
Originally posted by: brentman
you are printing the links no matter what the result of the conditional is....

<% If Request.ServerVariables("URL") ="/section1/" Then %>
Link 1.1
Link 1.2
Link 1.3
<% End If %>


needs to be like this...

<% If Request.ServerVariables("URL") ="/section1/" Then
response.write("Link 1.1 ")
response.write("Link 1.2 ")
response.write("Link 1.3 ")
End If %>


This is not necessary. I do the inline one frequently and it works just fine.