Forums

form to check input and return a message

cjmicro 13 Jun, 2010
We want to have a simple little quiz. I will give 4 answers and they can check one (or put in a number in a text field, whatever would be easiest).

I need it to check if it is the right answer and then return a message

"CORRECT" or "INCORRECT--TRY AGAIN!"

And let them check the boxes or write in their answer til they get it right. It does not have to send an email or do anything, just a fun little quiz.

If anyone can help I would appreciate it!

Thank you!
Cheryl
cjmicro 13 Jun, 2010
I found a script! Thought I would share. I am changing it a bit (do not want a "score" just the popup correct or incorrect).

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
var ans = new Array;
var done = new Array;
var yourAns = new Array;
var explainAnswer = new Array;

var score = 0;
ans[1] = "b";


explainAnswer[1]="Other information on the answer can go here";


function Engine(question, answer) {
yourAns[question]=answer;
}

function Score(){
var answerText = "How did you do?\n------------------------------------\n";
for(i=1;i<=1;i++){
   answerText=answerText+"\nQuestion :"+i+"\n";
  if(ans[i]!=yourAns[i]){
    answerText=answerText+"\nSorry, the correct answer was "+ans[i]+"\n"+explainAnswer[i]+"\n";
  }
  else{
    answerText=answerText+" \nCorrect! Good job. \n";
    score++;
  }
}

answerText=answerText+"\n\nYour total score is : "+score+"\n";

//now score the user
answerText=answerText+"\n ";
if(score<=0){
answerText=answerText+"Maybe you need to listen more and stop yakking!";
}
if(score>1){
answerText=answerText+"You have been around the hunt field!";
}

alert(answerText);

}
//  End -->
</script>


<DIV ALIGN="CENTER">
<h1>FHL Quiz</h1>
<b>Test your knowledge of Calls on the Horn</b>
<hr>

{flv}quiz1{/flv}  (my video goes here)<p>

<b>1. What is this horn call?</b><br>
<input type=radio name="q1" value="a" onClick="Engine(1, this.value)">a) Gone to 
Ground<br>
<input type=radio name="q1" value="b" onClick="Engine(1, this.value)">b) Gone 
Away<br>
<input type=radio name="q1" value="c" onClick="Engine(1, this.value)">c) 
Doubling<br>
<input type=radio name="q1" value="d" onClick="Engine(1, this.value)">d) Calling 
Whipper-In</p>

<CENTER>
<input type=button onClick="Score()" value="Well... How did I do?">
</CENTER>

</DIV>


I just put this all in form code area! The original quiz had 4 questions:

var score = 0;
ans[1] = "b";
ans[2] = "c";
etc.

explainAnswer[1]="Other information on the answer can go here";
explainAnswer[2]="Other information on the answer can go here";
etc.


Hope this can help someone else.
Cheers,
Cheryl

Cheryl
giochimoto 23 Jun, 2010
i am trying the script but i am not able to make it works
cjmicro 23 Jun, 2010
Sorry, I don't remember where I got it! You can do a search for free quiz script and see if you can find something with directions.

Cheryl
This topic is locked and no more replies can be posted.