Home / code / asp

How to show data to a user in ASP,

You can write to the webpage with response.write.

The example below uses 3 "build-in-functions" of asp.

<% @ language=vbscript %>
<HTML>
<HEAD>
 <TITLE>Response.write</TITLE>
</HEAD>
<BODY>

<%
response.write("It is now "& Now &"<br>")
response.write("Date: "& Date &"<br>")
response.write("Time "& Time &"<br>")
%>

</BODY>
</HTML>

The HTML-result could look like:

<HTML>
<HEAD>
 <TITLE>Response.write</TITLE>
</HEAD>
<BODY>

It is now 29/05/01 9:51:06<br>Date: 29/05/01<br>Time 9:51:06<br>

</BODY>
</HTML>

You have to remember that ASP does not send any line-breaks to the HTML code it generates. So everything is placed after each other.

In the second example we add variables.

<% @ language=vbscript %>
<HTML>
<HEAD>
 <TITLE>Response.write</TITLE>
</HEAD>
<BODY>
<H3>Example on response.write</H3>

<%
now1=now()
tomorrow=dateadd("d",1,now1)
twomonths=dateadd("m",2,now1)
later1=dateadd("h",3,now1)
later2=dateadd("n",10,now1)
wrong=dateadd("n",10,now1)

response.write("<TABLE BORDER=0>")
response.write("<TR><TD>Today is </TD><TD>"& now1 &"</TD></TR>")
response.write("<TR><TD>In 10 minutes </TD><TD>"& later2 &"</TD></TR>")
response.write("<TR><TD>Tomorrow it is </TD><TD>"& tomorrow &"</TD></TR>")
response.write("<TR><TD>In 2 months </TD><TD>"& twomonths &"</TD></TR>")
response.write("<TR><TD>In 3 hours it is </TD><TD>"& later1 &"</TD></TR>")
response.write("<TR><TD>Oops mistake </TD><TD>"& wrong1 &"</TD></TR>")
%>

</BODY>
</HTML>

When you test this code you'll see that wrong use of a variable (wrong<>wrong1) results in no value.

You can replace response.write(text) with <% =text %>
The following code gives the same result as the previous one.

<% @ language=vbscript %>
<HTML>
<HEAD>
 <TITLE>Response.write</TITLE>
</HEAD>
<BODY>
<H3>Example on response.write</H3>

<%
now1=now()
tomorrow=dateadd("d",1,now1)
twomonths=dateadd("m",2,now1)
later1=dateadd("h",3,now1)
later2=dateadd("n",10,now1)
wrong=dateadd("n",10,now1)
%>

<TABLE BORDER=0>
  <TR>
    <TD>Today is <TD>
    <TD><% =now1 %><TD>
  </TR><TR>
    <TD>In 10 minutes <TD>
    <TD><% =later2 %><TD>
  </TR><TR>
    <TD>Tomorrow it is <TD>
    <TD><% =tomorrow %><TD>
  </TR><TR>
    <TD>In 2 months <TD>
    <TD><% =twomonths %><TD>
  </TR><TR>
    <TD>In 3 hours it is <TD>
    <TD><% =later1 %><TD>
  </TR><TR>
    <TD>Oops mistake <TD>
    <TD><% =wrong1 %><TD>
  </TR>
</TABLE>

</BODY>
</HTML>

 

TOP

Latest script:

 

Books: