Assignment #6

I need to create a form that has some interaction with the user. The form should have these four elements:

  1. a text box asking for the user's name, with Put your name in here in the status bar, when the user fills it in
  2. a checkbox for Chocolate
  3. a checkbox for Vanilla, and when the user chooses one of the checkboxes, it will write You have chosen [flavor] in the status bar, indicating the user's choice
  4. a submit button which will pop up an alert box thanking the user for filling out the form
HTML file: Displayed by browser:
<body>

<h3>A form by Assignment</h3>
<form>
<h5>What is your name?</h5>
<input type="text" SIZE="30"
onFocus="window.status='Put your name in here';">
<br /><br /><hr />
<h5>Which flavor do you prefer?</h5>
<input type="checkbox" name="Chocolate" value="Flavor"
onFocus="window.status='You have chosen ' +name;"> Chocolate
<input type="checkbox" name="Vanilla" value="Flavor"
onFocus="window.status='You have chosen ' +name;"> Vanilla
<br /><br />
<input type="submit" onClick="alert('Thank you!');">
</form>

</body>

A form by Assignment

What is your name?



Which flavor do you prefer?
Chocolate Vanilla

By golly, I got it without looking at the answer website! However, I did refer back to my school notes on forms.

The status bar writing does not happen from the answer page (this does not work from any online location, as I mentioned before). It only works when running from a hard drive and only with Internet Explorer. My assignment's code was very similar to the answer page's code. They used onClick for the checkboxes while I used onFocus. Also, I used the variable name to say which flavor was chosen, while the answer page used the flavor's actual name. (I figured a form usually writes to a database, so using a variable made more sense to use.) I think I deserve an A, if grades are being handed out!

BackTable of ContentsNext