|
Assignment 5 - Control Structures,
Functions, the Response Object
The information needed to complete this assignment is covered in M&A
chapters 4 and 5, except the use of forms, which was covered in class
(and is covered in M&A chapters 8 and 9). I suggest that you have
your copy of M&A available as a reference while you work on your
labs. Name your scripts with the file names used in the examples.
1. ForNext.asp -- Write a script that
loops a number of times specified by the user. Your output should look like the
sample.
2. ForNextTable.asp -- It is frequently useful to write output into a table. Modify the previous
exercise to write your script output to a table. Your output should look like the
sample:
3. ForNextNested.asp -- Let's add some columns
to our table. Modify the previous
exercise to write a table with multiple rows and columns. Write the row and
column number in each cell. Your output should look like the
sample. Tip: Modify the previous exercise by nesting a For
Next "column" loop inside the existing "row" loop. The nested loop will produce the table
columns. 4. ValidInput.asp -- Our web users can
cause an error in any of the previous scripts simply by entering a non-numeric
value. We can prevent that by using a VBScript function to
check that the data is numeric. Modify exercise 2 with an
If Then statement that uses the IsNumeric function to check for numeric data. The IsNumeric function returns
"true" if the data is numeric and "false"
otherwise. The If Then statement that you will need to add is:
If IsNumeric(strRow) then
code block
else
code block
End If Your output should look like the
sample. 5. SalesCalc.asp -- Write a script that computes the sales
information shown in the example. Validate the form input data as in the previous exercise.
Do not show the calculations until input has been received from the
form. Your output should look like the
sample. 6.
HiddenTally.asp -- Modify CookieTally.asp to use a hidden form field
instead of a cookie to store the current tally. Tip:
The previous tally and the user's last input need to be added together before
the hidden field is written. To do this, add some
VBScript above the <form> tag to retrieve the data from the user's input and the current
tally. Assign these values to to local variables as you did for the
cookie tally last week. The syntax for storing ASP data in a hidden
form field is: <input type="hidden" name="strTally"
value="<% =dblTally + dblInput %>" > where
dblTally and dblInput are local variables. The hidden field may be
written anywhere inside the <form> </form> tags. You may find it useful to look at the
source
code in the example - you can see the hidden field inside the form. Also take
note of the two values
being passed in the querystring: strInput and strTally. 7.
FontPicker.asp
-- Modify the FunkyFont.asp
example from class to use five additional fonts. Here is the
source
(view source) code for the FunkyFont example. Steps:
-
All the images are stored in Professor. Sandvig's
account and may be referenced directly from there. The common
portion of each path is:
"<img src='http://yorktown.cbe.wwu.edu/sandvig/images/alphabet/"
Tip: You may wish to put the common part of the path into a variable
so that you don't have to repeat it many times within your code.
-
Each font/color combination is stored in a separate
folder and uses a slightly different naming convention. The
directory / naming convention for each font is (where x is the
character desired).
| Font |
Directory & File |
| Chunk Red |
chunk/red/x9.jpg |
| Deco Blue |
deco/blue/x1.gif |
| Animals |
animals/x4.gif |
| Elegant Red |
elegant/red/4x.gif |
| Funky |
funky/x3.jpg |
| Tape Punch |
punch/black/x7.gif |
-
Add radio buttons that allow the user to select one
of the six fonts.
-
Use a select case statement (documentation)
or an If...then...elseif statement to check the input from the radio
buttons and select the appropriate font.
-
Replace spaces in the message with <br> tags.
-
Optional: to insert line spaces into your HTML
source code (for appearance purposes) concatenate the VBScrit
vbcrlf statement into your output.
|