Show and hide elements with ASP

June 19, 2006

This trick will help may of the readers of this blog hide and show elements of a page or even run commands when a certain event happens.

you can do this by either passing the event trigger via a form event or a query string, in this instance we are going to do it by way of a query string.

The example we will use is a simple question and answer (What does ASP stand for), the code below is commented so it should be straight forward to understand.

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Show and hide elements with ASP – by Robbie Done</title>
</head>
<body>

What does ASP stand for?<br />

<ol>
<li><a href="?answer=w">A Super Person</a> <!–This line passes a query string back to this page, note that it woll pass ("?answer=w")–>
<li><a href="?answer=c">Active Server Pages</a> <!–This line passes a query string back to this page, note that it woll pass ("?answer=a")–>
<li><a href="?answer=s">Altitude Sensory Paddle</a> <!–This line passes a query string back to this page, note that it woll pass ("?answer=s")–>
</ol>
<br />
<%
If Request.QueryString("answer") <> "" Then 'The answer script is not called untill one of answers has been selected, it is basically saying in english – if the query string called answer is not equal to nothing then do this…
If Request.QueryString("answer") = "w" Then
Response.Write("Wrong Answer!"&"<br /><br />")
Else If Request.QueryString("answer") = "c" Then
Response.Write("You Are Correct"&"<br /><br />")
Else Response.Write("Are You Kidding? Try Again!"&"<br /><br />") 'This line of code is not like the above 2 request because if we know the query string is not equal to w nor c then it must be the remaining one of the 3
End If
End If
End If 'End of answer script
%>
<a href="?">Reset</a>
<!–This hyperlink will reset the page as it does not contain a querystring –>
</body>
</html>

And that's how easy it is to show and hide elements using ASP.

Entry Filed under: ASP. .

1 Comment Add your own

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Calendar

June 2006
M T W T F S S
    Jul »
 1234
567891011
12131415161718
19202122232425
2627282930  

Most Recent Posts