Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2012-04-12
5
Medium Priority
?
295 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:Martin Cotterill
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 2000 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:Martin Cotterill
ID: 37837946
Thanks for the replies both.

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

Dim vis1, vis2

Regards

Pb
0
 
LVL 34

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 34

Expert Comment

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

926 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