CSCI 895: CGI-Bin Programming
Programming assignment 2: Form Validation
Due 2/4
Requirements
In the first programming assignment, you created a simple form which input
the following information from a user:
-
Their name
-
Their gender
-
The month, day, and year in which they were born.
You are to enhance your form with JavaScript code which checks the content
of the form for correctness when the form is submitted. If the data does
not meet the following requirements, then the form should not be
submitted.
-
The user must enter a non-empty string for their name.
-
The user must choose one (and only one) gender.
-
The user must enter legal values for the month, day,
and year in which they were born. In particular:
-
The year must be a number between 1900 and 1999 inclusive.
-
The day must be a legal number for that particular month and
year
(for example, September 31 is not a legal date). Don't forget that February
29 is only legal for leap years!
If any of these rules are violated, an appropriate alertwindow
explaining the problem in an informative manner should be displayed. In
addition:
-
If the problem is a missing name or an illegal year, that text element
should be selected.
-
If the problem is an illegal date, the date entered by the user should
be included in the message alert window (for example,
"September 31, 1947 is not a legal date").
As always, your JavaScript code should be well documented.
What to Turn In
In order to preserve the security of your assignment, you are not
to post it the way that you did the first one. Instead, you are to turn
in a diskette containing your html file (which should be named hw2.htm
on the diskette).
You will be developing this program off line (this will be possible
since there is no additional CGI required for this assignment) on a PC.
That is, you can:
-
Write your code using some DOS/Windows text editor like the DOS
edit
program, or WordPad (make sure that you save it in text
format).
-
Test your code by opening a browser window and entering a:\hw2.htmas
the address.