Computer Science 180
Web Design

Fall 2011, Siena College

Lab 8: JavaScript Form Validation
Due: 1:30 PM, Monday, November 14, 2011

This week, you will gain even more experience with JavaScript by adding validation to a given form.

You may work alone or with a partner on this lab.

Additional Class Examples

Look back through the examples related to form validation and take a careful look at the examples we did not get to in class (agree.html, invoicenumber.html, and phonenumbers.html). Make sure you understand each. Pay special attention to the last one: the validation of phone numbers. phonenumbers.html.

You will be using most of the techniques you see in the examples, so be sure you understand them before continuing on.

Validating a Large Form

Save this document into your work area for this lab and open it in your favorite web authoring tool. It contains a fairly long form, layed out reasonbly nicely, but without any validation or other processing of the data entered.

Your primary task is to fill in the pressed JavaScript event handler. You should:

  1. Validate each field as appropriate. Some fields are required, others are not. Some should have only numeric values, or be in a specific format. In particular:
  2. Once all form elements validate properly, your function should add a nicely-formatted summary of the data entered into the <div>, and hide the form.

Much of what you need to add is in class examples. Use those! If you get stuck, especially on those parts that are a bit different from what you saw in class examples, don't hesitate to ask!

Submitting Your Work

Before 1:30 PM, Monday, November 14, 2011, submit your files for grading. There are three things you need to do to complete the submission: (i) make sure your page is uploaded properly to the class web space and is available at your URI, (ii) update your main index on the class web space to have links to the document you have created for this lab, and (iii) email a copy of your file to me at jteresco AT siena.edu. If you worked with a partner, you need only upload to the account of one of the team members, but each team member should link to the page on his or her own main index. Make sure your page validates properly as XHTML Strict.

Grading Sheet

This lab is worth 30 points, which are distributed as follows:

> FeatureValueScore
Required Components
Required fields must be provided 5
Optional fields may be left out 2
Phone number validation 3
Email address validation 3
Password validation 3
Credit card validation 4
Gender field processed properly 1
Terms of use checkbox required 1
Display of form information after passing validation 3
Style
XHTML document passes validation 2
Formatting of HTML text 1
Submission
Main index updated 1
Email submission 1
Total 30