This page contains the code for solarquiz_mail.asp, the active server page (ASP) that drives the Solar System Quiz with the email option. The ASP contains a scripting language called VBScript (a computer programming language). Unlike JavaScript embedded in an HTML page, the VBScript in an active server page is not passed to the client computer for processing. The web server processes the VBScript and assembles HTML pages for the client computer. Therefore, the student does not have access to any answers if they examine the HTML code.
The code for this page is essentially the same as the code for the Solar System Quiz (without email) with the addition of code for the email option. Therefore, comments will be made only for the email portion of the code. Consult the other web page for comments on the remainder of the code.
<% Language=VBScript%>
<%
'this script created by Jeff La Favre, John Carroll University, Cleveland, Ohio, USA,
jlafavre@jcu.edu
'copyright 2000, John Carroll University
'this version of the Solar System Quiz includes an email feature, which allows the student
the option to email the score to an address entered by the student
'start a session, name variables, and assign intital values
'the script below between If isempty and End if runs only when the page is first accessed
If isempty (Session ("QuestionsAnswered")) then
Session ("QuestionsAnswered") = 0
Session ("Correct") = 0
Session ("Question1") = 0
Session ("Question2") = 0
Session ("Question3") = 0
Session ("Question4") = 0
Session ("Question5") = 0
Session ("Question6") = 0
Session ("Answer_1") = " "
Session ("Answer_2") = " "
Session ("Answer_3") = " "
Session ("Answer_4") = " "
Session ("Answer_5") = " "
Session ("Answer_6") = " "
Session ("SendMail") = 0 this is an additional
variable used to decide if the score is to be emailed. The variable is assigned a
value of 0 initially, which equates to not sending the score by email. Further
below, on the quiz results page, the user has the option of clicking a submit button
labeled "yes", which ultimately changes the value of this varible to 1,
indicating that the score should be emailed.
End if
'variable below keeps track of the sequence of pages to display
Session ("QuestionsAnswered") = Session ("QuestionsAnswered") + 1
If Session ("QuestionsAnswered") = 1 then
%>
<html>
<head>
<!-- first HTML page displayed -->
<title>ASP Quiz</title>
</head>
<body bgcolor="#008080">
<div align="center"><center>
<table border="1" cellpadding="10" width="95%"
bgcolor="#E1D8A8" bordercolor="#800000">
<tr>
<td><font color="#800040">
<h1><center>Solar System Quiz</center></h1>
<font face="arial">
<p>Directions: answer each question. Then click on the
Continue button.
<!-- you must change the URL below to the location of this page -->
<form method="POST"
action="http://www.jcu.edu/language/asp/solarquiz_mail.asp">
<p>Question 1: What is the name of the largest planet in the solar system?
<select name="Answer1" size="1">
<option selected value="chose">-open and select answer-</option>
<option value="Saturn">Saturn</option>
<option value="Jupiter">Jupiter</option>
<option value="Earth">Earth</option>
</select></p>
<p>Question 2: Which planet has a distinctive ring system?
<p><input type="radio" name="Answer2"
value="Jupiter">Jupiter</p>
<p><input type="radio" name="Answer2"
value="Saturn">Saturn</p>
<p><input type="radio" name="Answer2"
value="Earth">Earth</p>
<p>Question 3: Which planet contains life?
<input type="text" size="7" name="Answer3"
value="">
</p>
<p><input type="submit" value="continue"
name="Action"></p>
</form>
</font>
</font>
</td>
</tr>
</table>
</center></div>
</body>
</html>
<%
'script below scores the answers from the first HTML page
ElseIf Session ("QuestionsAnswered") = 2 then
Session ("Answer_1") = Request.Form ("Answer1")
If Request.Form ("Answer1") = "Jupiter" then
Session ("Correct") = Session ("Correct") + 1
Session ("Question1") = Session ("Question1") + 1
End if
Session ("Answer_2") = Request.Form ("Answer2")
If Request.Form ("Answer2") = "Saturn" then
Session ("Correct") = Session ("Correct") + 1
Session ("Question2") = Session ("Question2") + 1
End if
Session ("Answer_3") = Request.Form ("Answer3")
If Request.Form ("Answer3") = "Earth" or Request.Form
("Answer3") = "earth" then
Session ("Correct") = Session ("Correct") + 1
Session ("Question3") = Session ("Question3") + 1
End if
%>
<html>
<head>
<!-- second HTML page -->
<title>ASP Quiz</title>
</head>
<body bgcolor="#008080">
<div align="center"><center>
<table border="1" cellpadding="10" width="95%"
bgcolor="#E1D8A8" bordercolor="#800000">
<tr>
<td><font color="#800040">
<h1><center>Solar System Quiz</center></h1>
<font face="arial">
<p>Directions: enter the name of each planet to the right of the photo. Then click
on the
Check Answers button.
<!-- you must change the URL below to the actual location of this page -->
<form method="POST"
action="http://www.jcu.edu/language/asp/solarquiz_mail.asp">
<p><img src="earthsm.jpg" width="125" height="94"
alt="photo loading">
<input type="text" size="7" name="Answer4"
value="">
</p>
<p><img src="jupitersm.jpg" width="125" height="94"
alt="photo loading">
<input type="text" size="7" name="Answer5"
value="">
</p>
<p><img src="saturnsm.jpg" width="125" height="94"
alt="photo loading">
<input type="text" size="7" name="Answer6"
value="">
</p>
<p><input type="submit" value="Check Answers"
name="Action"></p>
</form>
</font>
</font>
</td>
</tr>
</table>
</center></div>
</body>
</html>
<%
ElseIf Session ("QuestionsAnswered") = 3 then
%>
<html>
<head>
<!-- third HTML page -->
<title>Quiz Answers</title>
</head>
<body bgcolor="#008080">
<div align="center"><center>
<table border="1" cellpadding="10" width="95%"
bgcolor="#E1D8A8"
bordercolor="#800000">
<tr>
<td><font color="#800040">
<h1><center>Quiz Results</center></h1>
<font face="arial">
<%
'script below scores the answers from the second HTML page
Session ("Answer_4") = Request.Form ("Answer4")
If Request.Form ("Answer4") = "Earth" or Request.Form
("Answer4") = "earth" then
Session ("Correct") = Session ("Correct") + 1
Session ("Question4") = Session ("Question4") + 1
End if
Session ("Answer_5") = Request.Form ("Answer5")
If Request.Form ("Answer5") = "jupiter" or Request.Form
("Answer5") = "Jupiter" then
Session ("Correct") = Session ("Correct") + 1
Session ("Question5") = Session ("Question5") + 1
End if
Session ("Answer_6") = Request.Form ("Answer6")
If Request.Form ("Answer6") = "saturn" or Request.Form
("Answer6") = "Saturn" then
Session ("Correct") = Session ("Correct") + 1
Session ("Question6") = Session ("Question6") + 1
End if
'script below writes the results of quiz to this HTML page
If Session ("Question1") = 1 then
Response.Write "<p>Question 1 correct. The largest planet is
Jupiter.</p>"
Else
Response.Write "<p>Your answer to Question 1: " & Session
("Answer_1") & ". Correct answer: The largest planet is
Jupiter.</p>"
End if
If Session ("Question2") = 1 then
Response.Write "<p>Question 2 correct. The planet with a distinctive ring
system is Saturn.</p>"
Else
Response.Write "<p>Your answer to Question 2: " & Session
("Answer_2") & ". Correct answer: The planet with a distinctive ring
system is Saturn.</p>"
End if
If Session ("Question3") = 1 then
Response.Write "<p>Question 3 correct. The planet with life is
Earth.</p>"
Else
Response.Write "<p>Your answer to Question 3: " & Session
("Answer_3") & ". Correct answer: The planet with life is
Earth.</p>"
End if
If Session ("Question4") = 1 then
Response.Write "<p>Question 4 correct. Image of Earth.</p>"
Else
Response.Write "<p>Your answer to Question 4: " & Session
("Answer_4") & ". Correct answer: (image of) Earth.</p>"
End if
If Session ("Question5") = 1 then
Response.Write "<p>Question 5 correct. Image of Jupiter.</p>"
Else
Response.Write "<p>Your answer to Question 5: " & Session
("Answer_5") & ". Correct answer: (image of) Jupiter.</p>"
End if
If Session ("Question6") = 1 then
Response.Write "<p>Question 6 correct. Image of Saturn.</p>"
Else
Response.Write "<p>Your answer to Question 6: " & Session
("Answer_6") & ". Correct answer: (image of) Saturn.</p>"
End if
Response.Write "<p>Your Score: " & Session ("Correct") &
" correct out of 6.</p>"
%>
<!-- here the user decides if they want to email the score -->
The question below is printed at the bottom of the quiz results html
page.
Do you want to email this score to your instructor?
Note comment below. Send_Mail is a variable (actually
a hidden form field) used to decide if the score is to be emailed. If the user clicks the submit button (labeled "Yes") in the form
immediately below, then the variable Send_Mail will be assigned a value of 1.
<!-- the form below sets Send_Mail to a value of 1, which is required to display the
page for entering email addresses -->
<form method="POST"
action="http://www.jcu.edu/language/asp/solarquiz_mail.asp">
<Input type="hidden" name="Send_Mail" value="1">
<input type="submit" value="Yes"
name="Action"></p>
</form>
If the submit button in the form below is clicked, then the
variable Send_Mail will be assigned a value of 0.
<!-- the form below sets Send_Mail to a value of 0, which bypasses the score emailing
option -->
<form method="POST"
action="http://www.jcu.edu/language/asp/solarquiz_mail.asp">
<Input type="hidden" name="Send_Mail" value="0">
<input type="submit" value="No"
name="Action"></p>
</form>
</font>
</font>
</td>
</tr>
</table>
</center></div>
</body>
</html>
<% start of vbscript used to decide if score should be
emailed
Note comment below:
'here is script for deciding whether to email score or not
ElseIf Session ("QuestionsAnswered") = 4 then
Session ("SendMail") = Request.Form ("Send_Mail") i.e., the value in the hidden form field, Send_Mail, is assigned to the
variable SendMail.
If Session ("SendMail") = 1 then
Note comment below:
'this choice if email is to be sent
%>
<html>
<head>
Note comment below:
<!-- HTML page used to enter required information for emailing score -->
<title>Send Score</title>
</head>
<body bgcolor="#008080">
<div align="center"><center>
<table border="1" cellpadding="10" width="95%"
bgcolor="#E1D8A8"
bordercolor="#800000">
<tr><td>Fill in form then click Send Score button.
<!-- you must change the URL below to the location of this page -->
<form method="POST"
action="http://www.jcu.edu/language/asp/solarquiz_mail.asp">
Your name: <Input type="text" name="Name" value="">
<p>Your email address:<Input type="text" name="Sender"
value="">
<p>Your instructor's email address: <Input type="text"
name="SendTo" value="">
<input type="submit" value="Send Score"
name="Action"></p>
</form>
</td>
</tr>
</table>
</body>
</html>
<%
Else
Note comment below:
'this choice if email is not sent
%>
<html>
<head>
Note comment below:
<!-- Last HTML page to appear if user selects option not to send score to email address
-->
<title>Quiz Finished</title>
</head>
<body bgcolor="#008080">
<div align="center"><center>
<table border="1" cellpadding="10" width="95%"
bgcolor="#E1D8A8"
bordercolor="#800000">
<tr><td>
<p><a href="solarquiz_mail.asp">Take Quiz Again</a></p>
<p><a href="http://www.jcu.edu/language/lessons/lessons.htm">Return
to Lessons Page</a></p>
</td></tr></table></body></html>
<%
Session.Abandon
End if
Else
Note comment below:
'this is the mail script
Set objMail = CreateObject("CDONTS.NewMail")
Note comment below:
'line below formats email message: first sender's address, then address to send to, then
subject of message, then body of message
objMail.Send Request.Form ("Sender"), Request.Form ("SendTo"),
"Solar Quiz ASP Results", "Name: " & Request.Form
("Name") & " Score: " & Session ("Correct") &
" correct out of 6."
Set objMail = Nothing
%>
<html>
<head>
<!-- Last HTML page that appears if user selects option to send score to email address
-->
<title>Your Score has been sent</title>
</head>
<body bgcolor="#008080">
<div align="center"><center>
<table border="1" cellpadding="10" width="95%"
bgcolor="#E1D8A8" bordercolor="#800000">
<tr>
<td><font color="#800040">
<h1><center>Your Score has been sent</center></h1>
<font face="arial">
<p><p><a href="solarquiz_mail.asp">Take Quiz
Again</a></p>
<p><a href="http://www.jcu.edu/language/lessons/lessons.htm">Return
to Lessons Page</a></p>
</td>
</tr>
</table>
</center></div>
</body>
</html>
<%
Session.Abandon
End if
%>