Search Tools Links Login

A few cool ASP Tricks!

This will teach the users a little of the cool ASP tricks. Nothing to do with a database really, but They are still kinda cool just to test with!

Original Author: Travis Howle


Forms are great for collecting and handling data on your website. But how can you use ASP to make the most of your forms? Most webhosts provide standard scripts for form handling, but to make your site truly dynamic, it will not be long before you want forms to do something more than the average generic script offers.

In this tutorial, we will look at how we can collect and begin to process data from submitted forms on your website. Let`s start with a basic form (say call the file form.asp) as below with two fields, name and email address:

< form method="post" action="formhandler.asp" < br>name="whateveryouwant">< br>
Name: < input type="text" name="name">< br>

Email address: < input type="text" name="email">

< input type="submit" name="Submit" value="Submit">

< /form>

Now let`s begin to create formhandler.asp. The input from the form field called "name" is retrieved by calling request.form("name") and for the email form field, request.form("email"). Simple?

The first thing to consider is, what happens if someone leaves the fields blank. I imagine you don`t want to let them do that, so let`s set up a basic statement to handle that. We will be using If - Then - Else which is talked about in a later tutorial:

< %

If request.form("name")="" or request.form
("email")="" then

response.redirect "form.asp"


End if

% >

OK, so if either the name or email field were left blank, nothing is processed and the user is redirected back to the form to try again. In a later tutorial we may show you a nice way to highlight the fields that are required.

Right lets assume the user had the wit to actually input their name and email address. So what can you do with it? There are various possibilities: you could store the information in a database (more later on that), you could email it to yourself (again more later on this) or you could simply output the data on the webpage....ok that`s not very useful, but for the purposes of this basic tutorial it is what we will do.

So if you want to test this, set up your form.asp using the form code in the first codebox and set up formhandler.asp as follows:

< %

If request.form("name")="" or request.form
("email")="" then

response.redirect "form.asp"


End if

response.write "Name: " & request.form("name")
& "
Email: " & request.form("email")


% >

So simply, if both fields are filled in, it will output the Name and Email address. Note how you can combine text and ASP variables in your response.write statement as above.


There are several different ways of displaying dates.

You can also add and subtract from them as well.
I used one (1) in the examples below but, you can use any number you like.

Date 10/15/2003

< %=Date%>

Long Date Wednesday, October 15, 2003

< %=FormatDateTime(Now(),vbLongDate)%>

Adding to Long Date Thursday, October 16, 2003

< %=FormatDateTime(Now()+1,vbLongDate)%>

Subtracting From Long Date Tuesday, October 14, 2003

< %=FormatDateTime(Now()-1,vbLongDate)%>

Short Date 10/15/2003

< %=FormatDateTime(Now(),vbShortDate)%>

Adding To Short Date 10/16/2003

< %=FormatDateTime(Now()+1,vbShortDate)%>

Subtracting From Short Date Tuesday, October 14, 2003

< %=FormatDateTime(Now()-1,vbShortDate)%>

General Date 10/15/2003 4:32:27 PM

< %=FormatDateTime(Now(),vbGeneralDate)%>

Adding To General Date 10/16/2003 4:32:27 PM
< %=FormatDateTime(Now()+1,vbGeneralDate)%>

Subtracting From General Date 10/14/2003 4:32:27 PM

< %=FormatDateTime(Now()-1,vbGeneralDate)%>


To see if a specific file exists on the web server, then show the results to the user use the following code in an ASP page:

< %

Set fs=Server.CreateObject

If (fs.FileExists("c:inetpubwwwdefault.asp"))=true Then

c:winntcursorsThe DEFUALT.asp File exists.")

Response.Write("File c:winntcursorsThe File does not exist.")

End If

set fs=nothing

% >


To check to see if a drive is ready. Such as drive D for a CD copy or something type:

< %

dim fs,d,n

set fs=Server.CreateObject

set d=fs.GetDrive("c:")

n = "The " & d.DriveLetter

if d.IsReady=true then

n = n & " drive is ready."


n = n & " drive is not ready."

end if


set d=nothing

set fs=nothing

% >

I hope you liked it! And I hope it helped you :D Pleaes remember to vote! lol ;)

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 148 times




No attachments for this post

Loading Comments ...


No comments have been added for this post.

You must be logged in to make a comment.