Programming Assignment 2

Validating Forms with JavaScript

Background:

Creating forms with HTML is simple! You can use the <input> tag in conjunction with the attributes "text" for textbox, "radio" for round radio buttons, and "checkbox" for square checkboxes to allow the user to enter in information. The attribute "submit" is used to submit the form (to email or to a script for further processing) and "reset" is used to clear the form.

Javascript functions called "methods" in object oriented programming) can be used to check the form for errors. While completely "bullet-proofing" the information entered by the user is a difficult task, one can check for simple errors rather easily. The Javascript can be executed when the submit button is clicked by means of the <form> tag with the attribute: "onSubmit".

Specifications:

You will create a form that allows the user to enter a subscription for an imaginary newspaper. Click here for a sample of what your page should look like.

Your Javascript will check:

Once the form is verified, the user should get a message stating that the subscription has been entered.

Preparation:

Don't panic! This isn't hard. You can use this web page as a model: Click here for a model to work from. How was this done? (Hint: Go to the View menu and choose Page Source).

Getting Started:

Creating the Form: Hints:

Remember these programming rules:

Troubleshooting:

If you get a Javascript error, or if it just doesn't work. Read back over what you have written carefully. A single missing quote or typo can prevent it from working. Remember that case matters!

For An Extra Challenge:

Using the the function that checks for a valid email address as a model, see if you can write a function that checks for a valid phone number.

Click here to return
Copyright © 1999-2002 All Rights Reserved