DISC 3371 Midterm Answers --Fall 2001 Parks

1. (50 points) The server sends an HTML page that contains a form named showform. The form contains elements in the following order:

  1. a visible text box that allows the user to enter their user code with exactly 7 characters. This text box is initially blank and is named user_code
  2. a hidden variable that contains the actual user's 7 character code. This hidden variable is named actual.
  3. a hidden variable that contains the count of long distance phone calls a user made during a month. This hidden variable is named nc
  4. one hidden variable for each long distance phone call. This is the billing amount for the call. These hidden variables are not named. The number of the billing amount variables is equal to nc above.
  5. a visible button labelled "Show My Total Bill" with an onClick reference to a function named show_bill.

If the user_code begins the the letter "S", the user will receive a special 10% discount on any call with a billing amount greater than or equal to $20.00. The user is directed to enter their user_code and then press the "Show my Total Bill" button. The function show_bill first compares user_code to actual. If they match, then the function produces a new HTML page that shows:

  1. the user code
  2. the total billing amount (i.e., the sum of all billing amounts without discounts. There are nc items in the sum)
  3. the total amount of the special discount (this may be zero)
  4. the total billing amount with discounts (i.e., the sum of all billing amounts with discounts. There are nc items in the sum)
  5. the number of long distance calls
If the user_code does NOT match actual, then a page is produced that says only: "Wrong user code. Click Back and try again." Write the Javascript code for the function named show_bill. Do not edit or test the length of the user's entry. Show no HTML.


Answer (Click View Source to see the code). Click below to see it work.
User Code

2. (50 points) An HTML page is loaded that contains a form named vform. This form contains a single textbox named n and a button with the word "GO." The user is directed to enter a single integer that is greater than or equal to 5 and less than 21. When the user presses the "GO" button, a sub named fred is called. This sub produces a table with n rows and n columns with a one-pixel border.

1 1
1 2 2
2 3 3
3 4 4
4 5 5
5 6
Along the diagonal (the diagonal from the upper left cell to the lower right), cells contain the values 1 through n.

The space below each diagonal cell (except the last one) contains a single cell that spans the remainder of the column space (i.e., all the remaining rows). This spanning cell has: a background color of light gray ("#999999"); and has the integer from the diagonal cell above centered vertically in the space.

The space to the right of each a diagonal cell (except the last one) has a single cell that spans the reminder of the row space (i.e., all the remaining columns). The spanning cell has: a background color of medium gray ("#666666"); the integer from the row's diagonal cell centered horizontally in the space; and a white font color.

An example of the output is shown above for n=6. If the user enters a value greater than 20, the program sets n to 20. If the user enters a value less than 5, the program sets n to 5. Do not test the user's input for numeric. Show only the VBScript code for fred.

CAUTION: rowspan="0" and colspan="0" are both ignored by the browser. If a cell has rowspan="0" the rowspan attribute is ignored and the cell is displayed anyway. If a cell has colspan="0" the colspan attribute is ignored and the cell is displayed.


Answer (Click View Source to see the code). Click below to see it work.

Enter n >= 5 AND n < 21