Computer Science 180
Web Design

Fall 2011, Siena College

Lab 6: Working with Forms and JavaScript
Due: 1:30 PM, Monday, October 31, 2011

It's back to building web pages this week, as you will make use of the new techniques we have been looking at in class: HTML Forms and JavaScript event handlers.

You may work alone or with a partner for all parts of this lab.

In Lab: Experimenting with Form Controls

For this first part, you will use the new HTML elements corresponding to form controls to build a form that looks like this:

Strive to make the form appear precisely as in the image above. It should also meet these requirements:

In Lab: JavaScript Practice

Create a page that contains a simple HTML table with a header row, at least 3 regular rows, and at least 2 columns per row, and a caption.

Use buttons and JavaScript event handlers and functions to accomplish the following:

In Lab: Some Additional JavaScript Functionality

The w3schools.com page JavaScript How To shows some new bits of JavaScript functionality:

Create a page similar to the one in the demo, but which updates the date string to the current time each time the mouse is clicked on the displayed date.

Note: if you need to include double quotes inside the string you pass to document.write (and you do), you can put that string in single quotes instead:

  document.write('<p class="snoopy">');

In Lab: Accessing Form Data from JavaScript

Even before we start to consider how to submit forms with submit buttons, we can explore how to make use of the data in form controls using JavaScript event handlers.

Try out this example: helloperson.html. Most of this is familiar from previous examples, but there are a couple of items you have not yet seen.

We can take this a step further and display only the form when the page is first rendered, then only the message after the button has been clicked, as in this example: helloperson2.html.

The effect is to place what looks like a brand new message onto the page, and to remove the form from the page. We will look at all of them in upcoming examples. For now, the .value will be enough to do the following.

Mad Libs

Create a simple "Mad Lib" (spend a couple minutes looking at search results on this if you are not familiar with the concept) where you first display at least 5 text inputs labelled appropriately to inform your users of the kind of word or words required for each. When a button is pressed, the form is hidden and a silly message is displayed, using the values entered in the form (and highlighted in red) in the appropriate places.

Building Another Form

Develop a form that could be used to gather food preferences for the guests of a party. One possibility is a "pizza and wings" party. In this case, the form might ask guests how many slices of pizza they want and which of a collection of toppings they like, how many wings they expect to eat and their preference for how spicy they like wings, and whether they prefer diet or regular soda. You may use this example or come up with something with similar complexity using the same kinds of form controls needed here. You need not provide any JavaScript event handlers or submission handling capabilities - just the form layout.

Submitting Your Work

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

Grading Sheet

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

> FeatureValueScore
Required Documents
Web Design Race Entry Form 4
JavaScript Practice Table 4
Date Display Page 4
Mad Lib Page 6
Party Food Preference Form 6
Style
XHTML documents pass validation 3
Formatting of HTML text 1
Submission
Main index updated 1
Email submission 1
Total 30