MIS 3371 -- PARKS -- MIDTERM - FALL 2011 ANSWERS

Click "View", the "Source"

Greene County Tennessee
Taxlist 1809
By Milita District

1. (50 points) The textarea (named taxlist) is in a form named p1 that contains the names of the taxpayers in Greene County Tennessee in 1809. The list is divided into militia districts. There are 14 militia districts. A partial list shown to the left (many names have been removed for readability). The format of the list is:
  • Name of the militia district (e.g., Captain Evan Guin's District). A semicolon appears at the end of district's name. Followed by:
  • The taxpayers in the militia district with their last name followed by a comma and then then taxpayer's first name. A semicolon appears at the end of the taxpayer's name string. The number of taxpayers in each district varies from district to district. The last taxpayer name string in a district DOES NOT have a semicolon at the end.
  • Each district name is preceeded by a '*' -- except for the first district name (thus the '*' character separates the districts).
The button labelled "Execute p1" causes a javascript function named p1 to be executed. The function p1:
  1. creates a NEW HTML page on-the-fly
  2. this new page contains a 2 row, 14 column table with a one pixel border where:
    1. the first row has a gray background and contains the names of each of the 14 districts each in a table cell. Number each district starting at 1.
    2. the second row contains a list of the taxpayers (i.e., last name followed by a comma followed by the first name) for each of the 14 districts each in a table cell. Number each taxpayer's name in the district starting at 1. Vertically align the data in these table cells to the top.
Show NO HTML. Show ONLY the javascript code for the function named p1.
Size
2. (50 points) When the button labelled "execute p2" is clicked, the javascript function named p2 is executed. This function retrieves the value of the select labelled "Size" and is named sel. The seven visible <option> tags for this select are: Pick a Number Below; 9; 11; 13; 15; 17; and 19 AND the value clauses for these options are: 0; 9; 11; 13; 15; 17; and 19, respectively. This select is in a form named f2. The function p2 performs the following actions:
  1. retrives the value of the select box named sel. If the value of sel (or the .selectedIndex) is equal to zero, the display the error message: " You must Pick a Number Below".
  2. otherwise (i.e., sel value is: 9, 11, 13, 15, 17 or 19) construct a table with the number of rows AND columns equal to the number chosen in the select. The table should have a one pixel border.
  3. an image file named "green1x1.gif" is placed each table cell whenever:
    • the row is the "middle row" (all cells in the row)
    • the column is the "middle column" (all cells in the column)
    • along both diagonals of the table
    otherwise a single blank space is placed in the table cell. The image width should be set to the same number as the number of rows (or columns).
  4. when finished, place the table in the DIV block with id="p2out" (the image on this page uses 15 rows and columns).

Show NO HTML. Show ONLY the javascript code for the sub named p2.