Help for those using ASP to code menus!

Please note that official support for this menu version has now ceased. There are still plenty of users, though, and the forum is still running. Some of our long-time users may be able to help you out.
Post Reply
Grail Soulchaser
Beginner
Beginner
Posts: 1
Joined: Fri Jun 14, 2002 6:13 am
Location: Canada
Contact:

Help for those using ASP to code menus!

Post by Grail Soulchaser »

I've been reading through some topics from people asking for help with coding the menus for dynamic links through ASP. I use this on a couple of my sites, so I thought I'd share the secret.

The problem comes from Javascript confusing the ' character, and the " character. ASP uses the " character to enclose strings.. so in order to tell javascript the proper syntax, you need to use the character code.. which under ASP is ... chr(34) .

I've copied a section from my code to show how this works
It's rather large, so you may want to copy paste it so you can view it properly... hope this helps you all out...

This particular piece of code changes the menu based on whether a user is logged into the database, and what security level he has.. it's a simple site, so there are only 2 security levels.. makes it quite simple.

<%
If Session("CJLI") = True Then
Aopts = "addmenu(menu=[" & chr(34) & "admin" & chr(34) & "," &_
",,120,1," & chr(34) & chr(34) & ",style2,,,effect,,,,,,,,,,,,"
If Session("Sec") = 9 Then
Aopts = Aopts &_
"," & chr(34) & "Set Battle" & chr(34) & "," & chr(34) & "a-battles.asp swapimage=gfx/bShow.jpg;" & chr(34) & ",," & chr(34) & "Set Monthly Battle" & chr(34) & ",1" &_
"," & chr(34) & "Wipe Database" & chr(34) & "," & chr(34) & "wipedb.asp swapimage=gfx/bShow.jpg;" & chr(34) & ",," & chr(34) & "Wipe the Database" & chr(34) & ",1" &_
"," & chr(34) & "Post SP Results" & chr(34) & "," & chr(34) & "postsp.asp swapimage=gfx/bShow.jpg;" & chr(34) & ",," & chr(34) & "Post Single Player Results" & chr(34) & ",1" &_
"," & chr(34) & "Edit MP Scores" & chr(34) & "," & chr(34) & "editmp.asp swapimage=gfx/bShow.jpg;" & chr(34) & ",," & chr(34) & "Edit Multiplayer Scores" & chr(34) & ",1"
Else
Aopts = Aopts &_
"," & chr(34) & "Player Edit" & chr(34) & "," & chr(34) & "pedit.asp swapimage=gfx/bShow.jpg;" & chr(34) & ",," & chr(34) & "Edit your Player Info" & chr(34) & ",1" &_
"," & chr(34) & "Submit SP" & chr(34) & "," & chr(34) & "mailto:tiger01@cableone.net swapimage=gfx/bShow.jpg;" & chr(34) & ",,,1" &_
"," & chr(34) & "Report MP" & chr(34) & "," & chr(34) & "submit.asp swapimage=gfx/bShow.jpg;" & chr(34) & ",," & chr(34) & "Report Multiplayer Scores" & chr(34) & ",1"
End If
Aopts = Aopts & _
"," & chr(34) & "Logout" & chr(34) & "," & chr(34) & "cjlogout.asp swapimage=gfx/bShow.jpg;" & chr(34) & ",," & chr(34) & "Logout of Administration" & chr(34) & ",1" &_
"])"
Else
Aopts = "addmenu(menu=[" & chr(34) & "admin" & chr(34) & "," &_
",,120,1," & chr(34) & chr(34) & ",style2,,,effect,,,,,,,,,,,," & _
"," & chr(34) & "Login" & chr(34) & "," & chr(34) & "cjlogin.asp swapimage=gfx/bShow.jpg;" & chr(34) & ",," & chr(34) & "Login" & chr(34) & ",1" &_
"])"
End If
%>

After coding this piece.. all you need to do is in the Javascript section responsible for creating your menu, place the line:

<% Response.Write(Aopts) %>

and suddenly, it all works! :)

If anyone needs extra help.. feel free to ask me...
_______________________
Grail SoulChaser
(grail@viaticam.com)
Post Reply