Reply
Do these scripts work?
Old 04-28-2005, 11:25 AM Do these scripts work?
andrewsco's Avatar
Super Talker

Posts: 130
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
__________________
My Webpage: www.computer-tutorials.org
andrewsco is offline
Reply With Quote
View Public Profile Visit andrewsco's homepage!
 
When You Register, These Ads Go Away!
Old 04-28-2005, 12:44 PM
chrishirst's Avatar
Super Moderator

Posts: 13,643
Location: Blackpool. UK
if you are Win2k or XP Pro you can install IIS on the local machine for testing or you could download and install the cassini web server on your local machine.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 05-24-2005, 10:08 PM
Uche's Avatar
Extreme Talker

Posts: 174
Location: Nigeria/Lagos
Hello Andrew, if u need a ASP hosting i got one.. mind u it is a sub-domain u can just point ur domain to it.. d basic thing is 4 ur scripts to work rite ?
hit me back if u want that.. will gv it to u beside i don't use it
__________________
Life is just lyke a school where everybody goes to learn one or two thing. the more u school, the more u learn more about school..The more we live our lifes.. the more we learn more about life.
http://www.smartsoft-ng.com
Uche is offline
Reply With Quote
View Public Profile Visit Uche's homepage!
 
Reply     « Reply to Do these scripts work?
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 1.56954 seconds with 12 queries