DISC 3371 Midterm Fall 2002 Parks - Answers
Click View, then Source to see the code

The Houston Cheap News
Classified Advertisement Submission Form
(1) Pick an Ad Category
Automobile ($0.05 per word)
Real Estate ($0.06 per word)
Employment ($0.07 per word)
Personal ($0.08 per word)
(2) Enter your advertisement text below

(3) Check this box for BIG type face
       (for an additional $2.00)
(4) To get the price for your ad click
(5) To submit your ad click

Click these buttons to see the code execute

1. (50 points) An classified advertisement submission form is shown to the right. The user is directed to: pick an ad category; enter their advertisement text area; click the checkbox if the want BIG type; and then click the second button to submit the ad. If the user wants to see the price of the ad, they click the first button. The form containing the objects is named aform. The textarea is named tx.
If the user clicks the first button a sub named fred1 is called. This purpose of this sub is to count the words in the textarea (i.e., tx); calculate the advertisement price and display it to the user in a message box. No radio button is checked when the page is loaded. The user must check a radio button (if they do not, display the message "You must choose a category" and exit the sub). This sub manipulates the tx string as follows:
  1. removes any leading or trailing blanks
  2. replaces all occurences of ", " (a comma followed by a space) with a single comma
  3. replaces all occurences of ". " (a period followed by a single space) with a single period
  4. places a period at the end of the string if one does not appear
The sub then:
  1. counts the words in the tx string (Words can be separated by: a single blank space; a single comma; or a single period)
  2. calculates the price (use the price per word (for the radio button chosen) multiplied by the number of words found. Add $2.00 if the checkbox is checked.
  3. displays in a message box: "Your ad price is $xxx.xx". (show the calculated price NOT "xxx.xx")
  4. replaces the user's original text with the revised text string.
If the second button is clicked a sub named fred2 is called. This sub sets the form's action clause to: "http://auckland.bauer.uh.edu/students/parks/auto.asp" if Automobile was chosen; "http://auckland.bauer.uh.edu/students/parks/real.asp" if Real Estate was chosen; "http://auckland.bauer.uh.edu/students/parks/employ.asp" if Employment was chosen; or "http://auckland.bauer.uh.edu/students/parks/personal.asp" if Personal was chosen. The sub submits the form only if a radio button was checked. If no radio was checked display an error message and exit. Show only the VBScript for fred1 and fred2. Show no HTML. Assume two or more spaces, two or more commas or two or more periods never occur contiguously anywhere in the tx string.

2. (50 points) Three gif files (named white.gif, black.gif and gray.gif) are available that are each one pixel wide an one pixel tall. An HTML page shown at the bottom left contains: (1) a textbox (size=2) named rowcount; (2) a form named dform; (3) a button with the label "Draw It". When the user enters a value in the textbox and clicks the button, a function named drawit is executed. This function contains two arrays. The arrays are named wv and gv both of size 100.
The function first checks the value in the rowcount textbox to be sure it is a number -- if not an alert box is displayed that says "You must enter a numeric value" and the function terminates. The function places into each of the first rowcount elements of the arrays wv and gv a random integer between 0 and 120 (never zero and never 120). It then creates a new page with a borderless table containing rowcount rows. Each row contains one column that is 300 pixels wide and 5 pixels tall. Each row begins with the white.gif whose height is 5 pixels and whose width is equal to the value of wv for that row. Following the white.gif on the row is gray.gif which is also 5 pixels tall and whose width is the value of gv for that row. The remainder of the row is a black.gif whose width is 300 minus the sum of the wv and gv values for that row. Following the table show the percentage (not proportion) of the table space that is white, gray and black (i.e., three numbers). An example output is shown below to the right for rowcount=21. Show only the Javascript for drawit.
Number of Rows
Click this button
to see the code execute