Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

creating html page with ASP if statement 3

Status
Not open for further replies.

cic

Technical User
Apr 12, 2001
28
US
I need to know how to go about using an if statement to produce html. Below is a sample of what I have started but it isn't correct. I am not sure if I need to include a response.write. The else statement will create different html code. I am doing this because I don't want to have to create two html pages.

Thanks

<%Dim selection
selection=request.querystring(&quot;nationwide&quot;)%>
<%If selection = N then
<HTML>
<HEAD><TITLE></TITLE>
<META http-equiv=Content-Type content=&quot;text/html; charset=windows-1252&quot;>
</HEAD>
<BODY bgcolor=&quot;#FFFFFF&quot;>
<FORM method=&quot;post&quot; action=&quot;pubemail.asp&quot; name=&quot;publication&quot;>
<Input name=&quot;nationwide&quot; value=selection type=&quot;hidden&quot;>

<table cellspacing=1 cellpadding=5 width=552 border=0 align=&quot;left&quot;>
 
you have to use response.write

like this

<% response.write &quot;<HTML>&quot; %>
<% response.write &quot;<HEAD>&quot; %>
<% response.write &quot;<TITLE></TITLE>&quot; %>
<% response.write &quot;<META http-equiv=Content-Type content=&quot;text/html; charset=windows-1252&quot;>&quot; %>
<% response.write &quot;</HEAD>&quot; %>
<% response.write &quot;<BODY bgcolor=&quot;#FFFFFF&quot;>&quot; %>
<% response.write &quot;<FORM method=&quot;post&quot; action=&quot;pubemail.asp&quot; name=&quot;publication&quot;>&quot; %>
<% response.write &quot;<Input name=&quot;nationwide&quot; value=selection type=&quot;hidden&quot;>&quot; %>

<% response.write &quot;<table cellspacing=1 cellpadding=5 width=552 border=0 align=&quot;left&quot;>&quot; %>
 
why in the world would you want to open and close the scripts that many time??

when ever possible you should always open and close your scripts as little times as possible ---------------------------------------
{ str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
ptr = /sleep/gi;Nstr = str.replace(ptr,&quot;coffee&quot;);alert(Nstr); }
---------------------------------------
for the best results to your questions: FAQ333-2924

 
Another option is to escape the code and write the html.

Generally you don't want to leave and re-enter ASP sections very often because it will slow down processing of the page. Here are two examples:
Code:
<%
'who knows where this x and y came from, I made em up :)
If x > y Then
   %> <!-- We are now outside the asp script -->
   <html>
   <head>
   <title>Page 1!</title>
   </head>
   <body>
   <h1>Welcome to Page 1!</h1>
   </body>
   </html>
   <% 'everything after this is back inside the ASP script
Else
   %> <!-- Leaving the ASP swcript again -->
   <html>
   <head>
   <title>Page 2!</title>
   </head>
   <body>
   <h1>Welcome to Page 2!</h1>
   </body>
   </html>
   <% 'going back into ASP script
End If
%>

Ok that was escaping the script to write html tags, now lets write it using Response.Write:

If x < y Then
   Response.Write &quot;<html><head><title>This is Page 1!</title></head><body>&quot;
   Response.Write &quot;<h1>Welcome to Page 1!</h1>&quot;
   Response.Write &quot;</body></html>&quot;
Else
   Response.Write &quot;<html><head><title>This is Page 2!</title></head><body>&quot;
   Response.Write &quot;<h1>Welcome to Page 2!</h1>&quot;
   Response.Write &quot;</body></html>&quot;
End If

Now if you decide to go the route of using Response.Write than you probably shouldn't put your asp tags on every line, because this will still cause it to go in and out of the asp processing mode which you were trying to avoid.

Another popular method (ok, I do it, who knows if anyone else does :p )
is to include repeating things inside a function call or include file. Like in our example above I was repeating the top part quite a bit, so to keep the code looking clean lets define a header and footer function. The other advantage of this is that if I ever want to change them I only have to change them in one place and it will always be consistent.
Code:
If x < y Then
   ShowHeader
   Response.Write &quot;<h1>Welcome to Page 1!</h1>&quot;
   ShowFooter
Else
   ShowHeader
   Response.Write &quot;<h1>Welcome to Page 2!</h1>&quot;
   ShowFooter
End If

Function ShowHeader
   Response.Write &quot;<html><head><title>Welcome to my site</title></head><body>&quot;
End Function

Function ShowFooter
   Response.Write &quot;</body></html>&quot;
End Function

Obviously I probably have to little to need a header and footer function, but if you have a nice complicated layout that you want on every page then you could simply put it in functions and put those ni an include file. Then on every page you could include the file and call the ShowHeader and ShowFooter functions at the top and bottom.

Ok, i got caried away, sorry :)

-Tarwn ________________________________________________________________________________
Want to get great answers to your Tek-Tips questions? Have a look at faq333-2924
 
you're wright onpt, i didn't need to close the tags on all the lines, remember me?

I'm just a newbie, but i've seen an opportunity to help someone instead of just search for some help in here.
 
sounds like you took that badly. not intended, just wanted to let you know.

please find as many opportunities to jump into threads. That is the most powerful way to learn besides direction. ---------------------------------------
{ str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
ptr = /sleep/gi;Nstr = str.replace(ptr,&quot;coffee&quot;);alert(Nstr); }
---------------------------------------
for the best results to your questions: FAQ333-2924

 
not at all onpt, and i don't see any reason to take what you've said wrongly, i was only telling you that you're wright and that i try to help as much as i can the ones that just like me search for help here, and i'm just very pleased for the help that you and all the other guys give to people like me.
 
Please don't take anything onpnt and I say badly, we just see opportunities for improvement and take them, you should hear some of the stuff he has said about my poor web site :p

We're glad to see another member who's decided to stick around and help out, always welcome :)

Don't take my previous post as a correction, I was just bored and decided to embellish your point some more :)
I've been wiritng to many tutorials lately so I tend to ramble on quite a bit :)

-Tarwn

________________________________________________________________________________
Want to get great answers to your Tek-Tips questions? Have a look at faq333-2924
 
no problem guys, i'm not the kind of person to judge other people without knowing them.

can you help me on my post thread333-442790
 
CIC:

To answer your original post some tags were missing:

<%If selection = N then %>

<HTML>
<HEAD><TITLE></TITLE>
<META http-equiv=Content-Type content=&quot;text/html; charset=windows-1252&quot;>
</HEAD>
<BODY bgcolor=&quot;#FFFFFF&quot;>
<FORM method=&quot;post&quot; action=&quot;pubemail.asp&quot; name=&quot;publication&quot;>
<Input name=&quot;nationwide&quot; value=selection type=&quot;hidden&quot;>

<% End If %>
 
Thanks All. I appreciate everyones help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top