Solved

Turn If... Then... Else... to Case statement

Posted on 2012-04-12
5
285 Views
Last Modified: 2012-04-12
Hello all

I trying to create a menu for a site.

I've picked up this script to show and/or hide layers. It uses an If... Then... Else statement which in the example is fine. My menu will have up to eight entries so I think a Case statement may be the way to go.

My problem is I don't know anything about using Case in this instance so I'm looking for some help.

Here's the code.
<%
'declare 1 for each layer
Dim vis1, vis2

If request("show") = 1 Then
   vis1 = "visible"
   vis2 = "hidden"
Else
   vis1 = "hidden"
   vis2 = "visable"
End IF

%>

<div id="hide" style="visibility:<%=vis2%>;">this is my visable div</div>
<div id="test" style="visibility:<%=vis1%>;"> this is my hidden div</div>

<a href="testdiv.asp?show=1">show hidden layer</a>
<a href="testdiv.asp?show=2">show other layer</a>

Open in new window


Thanks in advance for the help.

Regards

Pb
0
Comment
Question by:Pantyboy
5 Comments
 
LVL 6

Expert Comment

by:wshark83
ID: 37837898
case when request("show") = 1 Then  vis1 = "visible"
        when request("show") = 1 Then  vis2 = "hidden"
        when request("show") <> 1 Then  vis1 = "hidden"
        when request("show") <> 1 Then  vis2 = "visable"
end
0
 
LVL 15

Accepted Solution

by:
pateljitu earned 500 total points
ID: 37837926
Please see this article explaining IF / ELSE as well as SELECT CASE statements:

http://www.w3schools.com/vbscript/vbscript_conditionals.asp


Sample:
Select Case request("show")
  Case 1
    vis1 = "visible"
    vis2 = "hidden"
  Case 2
    vis1 = "hidden"
    vis2 = "visible"
  Case else
    vis1 = "visible"
    vis2 = "hidden"
End Select
0
 
LVL 1

Author Comment

by:Pantyboy
ID: 37837946
Thanks for the replies both.

I take that the Dim statement remains the same. ie:

Dim vis1, vis2

Regards

Pb
0
 
LVL 32

Expert Comment

by:Big Monty
ID: 37837956
the code above is wrong, here is the correct code:
select case Request("show")
    case 1:
          vis1 = "visible"
          vis2  "hidden:
    case 2:
          vis1 = "hidden"
          vis2 = "visible"
    case "n/a":
          vis1 = ""
          vis2 = ""
    case else:
          '-- do whatever 
end select

Open in new window


this is just an example obviously, you'll need to fit it to your needs. the "case else" statement is the same as the else statement in a nested if/else block, it is not required.
0
 
LVL 32

Expert Comment

by:Big Monty
ID: 37837969
pateljitu's code is correct, i was referring to wshark83's code being wrong
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now