Forms and Javascript help

AcftMecH

OSNN Addict
Joined
17 Sep 2002
Messages
99
please see attached source code. this is not the real code of what I am doing, but it is the jist of what I am doing.

I have made a test (Q & A) webpage. I have an NAME input on the form. When it is submitted (graded via javascript) a new window will popup and give results. I want to add to the score results page the name the was inputed on the test, but cant seem to figure out on how to do it.

Alittle help would be appreciated.

Thanks!

AcftMecH
 

Attachments

  • test.txt
    4.3 KB · Views: 138
I rewrote your script for you :) there were too many errors and bugs to fix, it is now valid HTML too ;)

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
            "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  <meta http-equiv="Content-Script-Type" content="text/javascript">
  <title>Your Quiz</title>
  
<script type='text/javascript'>
<!--
//=================== NUMBER OF QUESTIONS AND HOW TO SCORE==================
var radioNum      = 5;              //Total number of questions
var qNum		= 4;			//Number of options per question
var maxPt         = 100;            //Total possible points
var YourScore	= 0;			//Starting score
var correct		= new Array();	//Answer key array
correct[0] = "D";
correct[1] = "B";
correct[2] = "D";
correct[3] = "A";
correct[4] = "C";
var answer		= new Array();	//User answer array

//============== GRADING THE TEST=============

var radioTax      = maxPt / radioNum;  //Points per question
var timeStart 	= new Date();

function CheckSum ()
  {
  for (i=0; i<qNum; i++) {
    if (document.answer.Q1[i].checked == true)
      answer[0] = document.answer.Q1[i].value; 
    if (document.answer.Q2[i].checked == true)
      answer[1] = document.answer.Q2[i].value;
    if (document.answer.Q3[i].checked == true)
      answer[2] = document.answer.Q3[i].value; 
    if (document.answer.Q4[i].checked == true)
      answer[3] = document.answer.Q4[i].value; 
    if (document.answer.Q5[i].checked == true)
      answer[4] = document.answer.Q5[i].value; 
    }
  
  for (i=0; i<radioNum; i++) {
    if (answer[i] == correct[i])
      YourScore += radioTax;
    }
    
//==============BUILDING THE SCORE CARD=============

  var scoreSheet = window.open("","","width=350,height=400,toolbars=no,status=no,scrollbars=yes,resizable=yes");
  var timeTurnIn = new Date();
  var firstname = document.answer.firstname.value;
  
  scoreSheet.document.writeln("<h1 align='center'>Test Results<\/h1>");
  scoreSheet.document.writeln("<b>Name:<\/b> " + firstname + "<br>");
  scoreSheet.document.writeln("<b>Time Started:<\/b> " + timeStart.getHours() + ":" + timeStart.getMinutes() + ":" + timeStart.getSeconds() + "<br>");
  scoreSheet.document.writeln("<b>Time Turned In:<\/b> " + timeTurnIn.getHours() + ":" + timeTurnIn.getMinutes() + ":" + timeTurnIn.getSeconds() + "<br>");
  scoreSheet.document.writeln("<b>Summary:<\/b><br><table width='100%' align='center'>");
  scoreSheet.document.writeln("<tr align='center'><td>Question<\/td><td>Answer<\/td><td>Your Answer<\/td><td>Status<\/td><\/tr>");

  for (var i=0; i<radioNum; i++) {
    scoreSheet.document.write("<tr align='center'><td>" + (i+1) + "<\/td><td>" + correct[i] + "<\/td><td>" + answer[i]);
    if (answer[i] == correct[i])
      scoreSheet.document.writeln("<td>Correct<\/td><\/tr>");
    else 
      scoreSheet.document.writeln("<td>Incorrect<\/td><\/tr>");
    }

  scoreSheet.document.writeln("<\/table><br>");
  scoreSheet.document.writeln("<b>Score:<\/b> " + YourScore + " out of " + maxPt + " possible points.<br>");
  scoreSheet.document.writeln("<b>Comments:<\/b> ");

  if      (YourScore == 100) { 
    scoreSheet.document.writeln("Way to go!!<br>"); 
    }
  else if (YourScore >= 80)  { scoreSheet.document.writeln("Pretty good!<br>"); }
  else if (YourScore >= 60)  { scoreSheet.document.writeln("Come on, you can do better than that!<br>"); }
  else                       { scoreSheet.document.writeln("You need to study harder.<br>"); }
  
  scoreSheet.document.close()
  scoreSheet.focus()
  }

//-->
</script>
</head>
<body>


<!-- ***************** QUESTIONS FORM  *******************-->

<form name="answer" onSubmit="return CheckSum(this)" method="post" action="">
<div>
Name: <input type="text" name="firstname"><br>
<hr>


1. If I have 3 apples, and I ate 2 of them, how many apples do I have left?
<br>
<input name="Q1" type="radio" value="A">A Four apples
<br>
<input name="Q1" type="radio" value="B">B Three apples
<br>
<input name="Q1" type="radio" value="C">C Two apples
<br>
<input name="Q1" type="radio" value="D">D One apple
<hr>



2. Ice will turn into water if the temperature is higher than __<sup>o</sup>C?
<br>
<input name="Q2" type="radio" value="A">A 50
<br>
<input name="Q2" type="radio" value="B">B 0
<br>
<input name="Q2" type="radio" value="C">C 100
<br>
<input name="Q2" type="radio" value="D">D 32
<hr>



3. Which of the following is correct?
<br>
<input name="Q3" type="radio" value="A">A The Sun is surrounding the Earth
<br>
<input name="Q3" type="radio" value="B">B The Earth is the center of the Solar System
<br>
<input name="Q3" type="radio" value="C">C The Earth is surrounding the Moon
<br>
<input name="Q3" type="radio" value="D">D The Earth is surrounding the Sun
<hr>



4. Which of the following is NOT a part of speech?<br>
<input name="Q4" type="radio" value="A">A Bold
<br>
<input name="Q4" type="radio" value="B">B Verb
<br>
<input name="Q4" type="radio" value="C">C Preposition
<br>
<input name="Q4" type="radio" value="D">D Noun
<hr>



5. Who is the first president of United States?
<br>
<input name="Q5" type="radio" value="A">A Bill Clinton
<br>
<input name="Q5" type="radio" value="B">B Abraham Lincoln
<br>
<input name="Q5" type="radio" value="C">C George Washington
<br>
<input name="Q5" type="radio" value="D">D Thomas Jefferson
<hr>

<input type='submit' value='GRADE IT'>
<input type='reset' value='Erase All Answers'>

</div>
</form>
</body>
</html>
 
Wow

j79zlr, you da man! You didnt have to go through all of that trouble. But in the end, I got the results I wanted. MUCH MUCH appreciated! some of the errors you did, i didnt worry about simply because it was a working script. I am doing a project for work so I am having like 150+ questions....eeeeeck. i have one test made currently with 100 questions, that works good.

Anyways, enough with the babbling... Thanks again!

AcftMecH
 

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,621
Latest member
naeemsafi
Back