Hi. I am wondering a few things. Firstly does anyone have any webspace that supports ASP? I really cant and dont have time to be downloading all the stuff for it due to other pieces of coursework. Secondly my site doesnt support asp so I cant upload the stuff.
Secondly most of the code I *think* works but as I said I havent tested it. Could anyone who knows what they are doing have a look, and make any changes where necessary? to see if it works?
quizStore.asp
Code:
<%
' Instantiate objects and initialise variables
set fso = Server.CreateObject("Scripting.FileSystemObject")
ResultFile = Server.MapPath("quizResults.txt")
set myFile = fso.OpenTextFile(ResultFile,8,True)
' Get the corresponding values from the names/value pairs
name = Request.Form("name")
email = Request.Form("email")
question1 = Request.Form("question1")
question2 = Request.Form("question2")
question3 = Request.Form("question3")
score = Request.Form("finalScore")
' Append entries to text file
myFile.WriteLine("Question 1: " & question1)
myFile.WriteLine("Question 2: " & question2)
myFile.WriteLine("Question 3: " & question3)
myFile.WriteLine("Name: " & name)
myFile.WriteLine("E-mail: " & email)
myFile.WriteLine("Score: " & score)
'Stop the output process
myFile.Close
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml/DTD/xhtml1-stricy.dtd">
<html>
<head>
<title>Quiz results</title>
<meta http-equiv="content-type"content="text/html;charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="stylesheet.css" />
</head>
<body>
<h1>Your answers</h1>
<p>Name: <%= name %> <br />
E-mail: <%= email %> <br />
</p>
<hr />
<p>Question 1: <%= question1 %></p>
<p>Question 2: <%= question2 %></p>
<p>Question 3: <%= question3 %></p>
<p>
<a href="quizResults.txt">Text file</a> <br />
<a href="quiz.html">Quiz</a> <br />
</p>
</body>
</html>
quizCheck.js
Code:
var score = 0;
function validate()
{
var name = document.forms[0].user_name.value;
var email = document.forms[0].user_email.value;
if(name == "")
{
alert('Please enter name');
return false;
//An alert is used if the name is left blank
}
else if(email == "" )
{
alert('Please enter email');
return false;
//An alert is used if the email address is left blank
}
else
{
mark();
return true;
// Calls the function mark()
}
}
function mark()
{
// Variable initialisation
var score = 0;
//question 1
if(document.forms[0].question1_select.value=="Apache")
// Checks to see if the answer is correct
{
score++;
// If it is the increment the score by 1
}
//question 2
if(document.forms[0].question2_radio[2].checked)
{
score++;
}
//question 3
if (document.forms[0].question3_check[1].checked)
{
score++; //adds a mark if 'H1' is selected
}
if(document.forms[0].question3_check[3].checked)
{
score++; //adds a mark if 'DIV' is selected
}
if(document.forms[0].question3_check[0].checked)
{
score = score - 0.5; //takes off 1/2 a mark if 'EM' is selected
}
if(document.forms[0].question3_check[2].checked)
{
score = score - 0.5; //takes off 1/2 a mark if 'IMG' is selected
}
if(score < 0)
{
score = 0;
// This ensures that noone can have less than 0/4 marks.
}
window.alert(document.forms[0].name.value + ' with ' + document.forms[0].email.value + ' scored a total ' + score + ' out of 4 ');
return true;
// This gives an alert with the scores in.
}
}
quiz.html
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml/DTD/xhtml1-stricy.dtd">
<html>
<head>
<title>Quiz</title>
<meta http-equiv="content-type"content="text/html;charset=iso-8859-1" />
<script type="text/javascript" src="quizCheck.js"></script>
<link rel="stylesheet" type="text/css" href="stylesheet.css" />
</head>
<body>
<form method="post" id ="task1" action ="quizStore.asp" onsubmit="return validate();" >
<h1>Netskills Quiz</h1>
</p>
<h2>Which web server software is thought to run over 65% of the world's websites?</h2><br />
<input type="radio" name="question1" value="Apache" />Apache <br />
<input type="radio" name="question1" value="Microsoft IIS" />Microsoft IIS <br />
<input type="radio" name="question" value="NCSA" />NCSA <br />
<input type="radio" name="question" value="IBM HTTP Server" />IBM HTTP Server <br />
</p>
<p><h2>Which of the following is not a type of CSS positioning?</h2><br />
<select name="question2">
<option value="Question not answered">Please pick an answer</option>
<option value="Static">Static</option>
<option value="Absolute">Absolute</option>
<option value="Flexible">Flexible</option>
<option value="Fixed">Fixed</option>
</select>
</p>
<p>
Which two of the following are block-level HTML elements?
<br />
<input type="checkbox" name="question3" value="EM" />EM
<br />
<input type="checkbox" name="question3" value="H1" />H1
<br />
<input type="checkbox" name="question3" value="IMG" />IMG
<br />
<input type="checkbox" name="question3" value="DIV" />DIV
<br />
</p>
<p>Enter your email Address:
<input type="text" name="email" />
<br />
Enter your Name:
<input type="text" name="name" />
<br />
</p>
<p>
<input type="submit" value="Submit" />
<input type="reset" value="Reset" />
</p>
<p>
<input type="hidden" name="finalScore" />
</p>
</form>
</body>
</html>
Thanks
Sco
|