![]() |
ASP beginner’s tutorial |
PART FIVE |
|
Something more useful |
|
At some point, you may want to ask a visitor to your site for
their date of birth. The non-ASP way would be to create some
drop-down
View this HTML in your browser: dob.htm As you can see, this could take some time to create by hand!
Using ASP, you could create the option lists automatically!
You need to a loop
function to iterate through the list and output the values
using the Response.Write method. We will use the simplest
For the day:
The new bits are:
Whilst not strictly necessary, it is good practice to tell the server which variables you are going to use in advance. It is also good for other people reading you code to add comments using the single quote (‘). Anything after a single quote is ignored by the server.
This means “repeat the bit of code by increasing the value
of variable
This means output the HTML tag For the month:
Note that a variable only needs to be declared once and can be reused. If you declare it twice, you will get an error! The new bit is:
This function displays the name of the month rather than just
the month number, for example, For the year:
The new bit is:
The counter can start at any value and this assumes a start year of 1901 and loops until the current year:
Try this using the demonstration file: dob.asp Hopefully, you will agree that this is quicker than hand coding
the HTML!
|
|
| Next: ASP and forms | |
| © 2005 | Index: Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 |