Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FORM QUESTION 1

Status
Not open for further replies.

techgrrl

Programmer
Jul 27, 2001
4
US
I have to create a script for a ten question quiz. I would like to design it as a form, so that when the user submits the quiz (after answering all 10 questions) the form goes to an inbox. This part I have no problem with. What I am confused about is the following: I would like a pop up window to appear after the user answers each question notifying the user if the answer that they submitted was right or wrong, along with the correct answer. However, I would like the form to be submitted after all questions are answered, can this be done??

I'm new to this and appreciate any help!
 
Here's a start, but I can't finish it now. I'll come back later to help!

Code:
<html>
<head>
function check(number){
var their_answer = &quot;document.QA.&quot;+number+&quot;.value&quot;;
if(their_answer == myQuestions[number])alert(&quot;Correct&quot;);
else{alert(&quot;Incorrect&quot;);}
}
</head>
<body>
<form name=&quot;QA&quot;>
<script>
/*** Fill these arrays in respectively ***/
myQuestions = new Array (&quot;Trees are green&quot;,&quot;music is good&quot;);
myAnswers = new Array (&quot;true&quot;,&quot;false&quot;);
if(myQuestions.length == myAnswers.length)
{
for(var temp=0;temp<myQuestions.length;temp++)
  { 
  document.write(myQuestions[temp]=&quot;<input type=text name=&quot;+temp+&quot;><input type=button onClick=\&quot;check(temp);\&quot;><br>&quot;);
  }
}
else
{
alert(&quot;Number of Questions and Answers is different!&quot;);
}
</script>
</body>
</html>
 
I know theres errors, but if you can wait i'll be back to fix them, this is fun!
 
<html>
<head>
<script>
/*** Fill these arrays in respectively ***/
myAnswers = new Array (&quot;green&quot;,&quot;orange&quot;);

function check(number){
var their_answer = 'document.qa.'+q+'.value';
if(their_answer == myAnswers[number])
{alert(&quot;Correct&quot;);}
else
{alert(&quot;Incorrect&quot;);}
}
</script>
</head>
<body>
<form name=&quot;qa&quot;>
<table>
<tr><td>1) How do you spell green?</td><td><input type=&quot;text&quot; name=&quot;q1&quot;></td><td><input type=&quot;button&quot; value=&quot;Check&quot; onClick=&quot;check(0);&quot;></td></tr>
<tr><td>1) How do you spell green?</td><td><input type=&quot;text&quot; name=&quot;q2&quot;></td><td><input type=&quot;button&quot; value=&quot;Check&quot; onClick=&quot;check(1);&quot;></td></tr>
</table>
</form>
</body>
</html>

Not sure why this doesn't work, but i'm not going to have the time to figure out why, sorry! Maybe someone else can troubleshoot this for you?

Try these:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top