Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 5 123 ... LastLast
Results 1 to 15 of 64
  1. #1
    New Coder
    Join Date
    Jul 2005
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Once clicked: The score will appear

    I have a simple problem that I can't solve. I know that you guys might know how to solve it. I'm using an extension of dreamweaver called Coursebuilder. I'm making an online-examination to improve education especially in a far region of Asia where there's poor quality of education in there. Now, I'm making a multiplication choice type of exam with radio buttons in it and when the "check answer" was clicked, the answer will be explained. It is already done, but the problem is the feedback score. I can't make a feedback score... example the examination is 40/100 score it must appear on the screen at once after a click of a certain button. That's my only problem for now. It will be used in CD format and online. what should i do? All I need is to know how will I put a button that once it was clicked the score in the examination will appear. I'm an amateur web designer, I need your help.

    Thanks please help me.
    my email is: boyaskman@yahoo.com

  • #2
    Super Moderator sage45's Avatar
    Join Date
    May 2002
    Posts
    1,060
    Thanks
    0
    Thanked 13 Times in 13 Posts
    A link to your site to look at your code would be helpful.

    -sage-
    HTML & CSS Forum Moderator

    "If you don't know what you think you know, then what do you know."
    R.I.P. Derrick Thomas #58
    1/1/1967 - 2/8/2000

  • #3
    New Coder
    Join Date
    Jul 2005
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    how ??? what i mean is this..

    example

    1. what is .... blah blah

    radio button a.) answer 1
    radio button b.) answer 2
    radio button c.) answer 3

    (button "check answer")

    2. what is blah blah ? ?(question number 2)

    radio button a.) answer 1
    radio button b.) answer 2
    radio button c.) answer 3

    (button "check answer")

    3.

    4.

    5.

    ..... 50.
    -----------------------

    ( CHECK SCORE )


    then all questions will be 1-50 so to know the score in the entire examination, there should be a button "SCORE" to click and something will appear in the scren telling you of your score. What should I do? Please instruct me. This is important.

    Thanks again.
    my email is: boyaskman@yahoo.com

  • #4
    Super Moderator sage45's Avatar
    Join Date
    May 2002
    Posts
    1,060
    Thanks
    0
    Thanked 13 Times in 13 Posts
    I'm sorry, I assumed you had something in place and it was giving you hiccups... Well your problem is easily solved using a bit of javascript, however, since javascript is a client-side construct, the people taking the quiz would be able to cheat or change their answers. If this is not a big concern for you, then javascript would be the easiest to implement...

    I will move your post to the javascript forum so that they can help you over there...

    -sage-
    HTML & CSS Forum Moderator

    "If you don't know what you think you know, then what do you know."
    R.I.P. Derrick Thomas #58
    1/1/1967 - 2/8/2000

  • #5
    New Coder
    Join Date
    Jul 2005
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hey sage,
    thanks for answering my posts. my problem is i don't use javascript that much. there is no concern in cheating.. that is just a self-examination. they read a book and they should know how much they have learned. All they have to do is not to count all their correct answer, there must be a way to show the score. What is the script to that ?
    my email is: boyaskman@yahoo.com

  • #6
    Regular Coder
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    375
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Although it was for a Quiz with a completely different type of content (a lighthearted survey), I just made a script for that in response to another question. The format should be extremely adaptable to your purposes, the script and the markup are fairly well commented for ease of use. Let me know if you need other features/modifications you cannot figure out for yourself: Quiz

    - J

    Edit: Or better yet, try this one


    Code:
    <html>
    <head>
    <title>State Capitols Quiz</title>
    <style type="text/css">
    .chkans {
    margin:10px 10px -5px 0;
    } 
    
    span.chkans {
    position:relative;
    top:5px
    } 
    
    * html span.chkans {
    top:2px
    } 
    </style>
    <script type="text/javascript">
    /*/////////////////////////////
    * Quiz Evaluation Script © jscheuer1
    * permission to use granted
    * this credit must stay intact
    /////////////////////////////*/
    
    //Set number of questions
    var numQuest=3
    
    ////////////////Stop Editing///////////////
    var ie=document.all
    function showAnswer(el,ans){
    ie? ie[el].innerHTML='The answer is: '+ ans : document.getElementById(el).innerHTML='The answer is: '+ ans
    }
    
    function addup()  {
    var q, right, statement, total=0
    questions=new Array();
    for (i = 0; i < numQuest; i++)
    questions[i]=0
    if (document.forms.quiz.q1['right1']){
    for (i = 0; i < numQuest; i++){
    q="q"+(i+1)
    right="right"+(i+1)
    if (document.forms.quiz[q][right].checked)
    questions[i]=1
    }
    }
    else if (document.getElementById){
    for (i = 0; i < numQuest; i++){
    right="right"+(i+1)
    if (document.getElementById(right).checked)
    questions[i]=1
    }
    }
    else
    return;
    for (i = 0; i < numQuest; i++)
    total += questions[i]
    /*/////////////////////////////////////////////////
    Set score response below.
    ///////////////////Edit Below to Suit/////////////*/
    statement='You scored '+ total +' out of '+ numQuest +' correct, '+ Math.round(total/numQuest*100) +'%'
    /////////////////Stop Editing///////////////////
    ie? ie.results.innerHTML=statement : document.getElementById('results').innerHTML=statement
    }
    function clearR(){
    ie? ie.results.innerHTML='' : document.getElementById('results').innerHTML=''
    for (i = 0; i < numQuest; i++)
    ie? ie["ans"+(i+1)].innerHTML='' : document.getElementById("ans"+(i+1)).innerHTML=''
    }
    </script>
    </head>
    <body>
    <h1>State Capitols Quiz</h1>
    This page will tell what you know about state capitols.<br><br>
    <h2>Directions:</h2>
    Click on the correct answer.<br><br>
    <hr>
    <form name="quiz">
    <!--Edit and/or add questions below-->
    <!--Be sure to follow the format shown-->
    Question 1:<br>
    What is the capitol of Pennsylvania?<br>
    <input id="right1" type="radio" unchecked name="q1"><label for="right1">Harrisburg</label><br>
    <input id="w1a" type="radio" unchecked name="q1"><label for="w1a">Oswego</label><br>
    <input id="w1b" type="radio" unchecked name="q1"><label for="w1b">Philadelphia</label><br>
    <input id="w1c" type="radio" unchecked name="q1"><label for="w1c">Denver</label><br>
    <input class="chkans" type="button" value="Check Answer" onclick="showAnswer('ans1','Harrisburg')">&nbsp;<span id="ans1" class="chkans"></span>
    <br>&nbsp;<br>
    Question 2:<br>
    What is the capitol of New Jersey?<br>
    <input id="w2a" type="radio" unchecked name="q2"><label for="w2a">Princeton</label><br>
    <input id="w2b" type="radio" unchecked name="q2"><label for="w2b">North Orange</label><br>
    <input id="right2" type="radio" unchecked name="q2"><label for="right2">Trenton</label><br>
    <input id="w2c" type="radio" unchecked name="q2"><label for="w2c">Labrador</label><br>
    <input class="chkans" type="button" value="Check Answer" onclick="showAnswer('ans2','Trenton')">&nbsp;<span id="ans2" class="chkans"></span>
    <br>&nbsp;<br>
    Question 3:<br>
    What is the capitol of Montana?<br>
    <input id="w3a" type="radio" unchecked name="q3"><label for="w3a">Billings</label><br>
    <input id="right3" type="radio" unchecked name="q3"><label for="right3">Helena</label><br>
    <input id="w3b" type="radio" unchecked name="q3"><label for="w3b">Shelby</label><br>
    <input id="w3c" type="radio" unchecked name="q3"><label for="w3c">Tabasco</label><br>
    <input class="chkans" type="button" value="Check Answer" onclick="showAnswer('ans3','Helena')">&nbsp;<span id="ans3" class="chkans"></span>
    <br>&nbsp;<br>
    <!--End of Questions-->
    <hr><br>
    <input type="button" value="See Score" onclick="addup()">&nbsp;&nbsp;<span id="results"></span><br>&nbsp;<br>
    <input type="button" value="Start Again" onclick="reset();clearR()">
    </form></body></html>
    Last edited by jscheuer1; 07-07-2005 at 08:30 AM.

  • #7
    Regular Coder
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    375
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm just about finished modding up this script so that it will write its own answers and questions from an array, saving whoever uses it a lot of time. If interested, stay tuned to this space.

  • #8
    Regular Coder
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    375
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here it is:

    Code:
    <html>
    <head>
    <title>State Capitols Quiz</title>
    
    <style type="text/css">
    .chkans {
    margin:10px 10px -5px 0;
    } 
    
    span.chkans {
    position:relative;
    top:5px
    } 
    
    * html span.chkans {
    top:2px
    } 
    </style>
    
    </head>
    <body>
    <h1>State Capitols Quiz</h1>
    This page will tell what you know about state capitols.<br>
    <h2>Directions:</h2>
    Click on the correct answer.<br><br>
    
    <script type="text/javascript">
    /*/////////////////////////////
    * Quiz Writing & Scoring Script
    * © 2005 John Davenport Scheuer
    * jscheuer1TAKEOUTCAPSFOREMAIL@comcast.net
    * permission to use granted
    * this credit must stay intact
    /////////////////////////////*/
    
    //Set to 0 for no answers given away
    //Set to 1 to allow peeking
    var allowPeeking=1
    
    //Set to 0 for no Starting Over without refresh
    //Set to 1 to allow Easy Do Overs
    var allowDoOvers=1
    
    questions=new Array();
    //Set Questions and Answers Arrays Below.
    //Questions come first.  Then come the answer pairs:
    //Follow the right answer with "right", all wrong ones with ""
    questions[0]=["What is the capitol of Pennsylvania?", "Harrisburg", "right", "Oswego", "", "Philadelphia", "", "Denver", ""]
    questions[1]=["What is the capitol of New Jersey?", "Princeton", "", "North Orange", "", "Trenton", "right", "Labrador", ""]
    questions[2]=["What is the capitol of Montana?", "Billings", "", "Helena", "right", "Shelby", "", "Tabasco", ""]
    questions[3]=["What is the capitol of New York?", "Syracuse", "", "New York City", "", "Buffalo", "", "Albany", "right"]
    questions[4]=["What is the capitol of Kansas?", "Atchison", "", "Topeka", "right", "Dodge City", "", "Manhattan", ""]
    questions[5]=["Are we having fun yet?", "Yes", "right", "No", ""]
    
    ////////////////Stop Editing///////////////
    
    for (i = 0; i < questions.length; i++){
    for (j = 0; j < questions[i].length; j++){
    if (questions[i][j]=="")
    questions[i][j]=("w"+i)+j
    if (questions[i][j]=="right")
    questions[i][j]="right"+i
    }
    }
    var ie=document.all
    function showAnswer(el,ans){
    ie? ie[el].innerHTML='The answer is: '+ ans : document.getElementById(el).innerHTML='The answer is: '+ ans
    }
    
    function addup()  {
    var q, right, statement, total=0
    quizQuests=new Array();
    for (i = 0; i < questions.length; i++)
    quizQuests[i]=0
    if (document.forms.quiz.q0['right0']){
    for (i = 0; i < questions.length; i++){
    q="q"+i
    right="right"+i
    if (document.forms.quiz[q][right].checked)
    quizQuests[i]=1
    }
    }
    else if (document.getElementById){
    for (i = 0; i < questions.length; i++){
    right="right"+i
    if (document.getElementById(right).checked)
    quizQuests[i]=1
    }
    }
    else
    return;
    for (i = 0; i < questions.length; i++)
    total += quizQuests[i]
    /*/////////////////////////////////////////////////
    Set score response below.
    ///////////////////Edit Below to Suit/////////////*/
    statement='You scored '+ total +' out of '+ questions.length +' correct, '+ Math.round(total/questions.length*100) +'%'
    /////////////////Stop Editing///////////////////
    ie? ie.results.innerHTML=statement : document.getElementById('results').innerHTML=statement
    }
    function clearR(){
    ie? ie.results.innerHTML='' : document.getElementById('results').innerHTML=''
    for (i = 0; i < questions.length; i++)
    if (allowPeeking)
    ie? ie["ans"+i].innerHTML='' : document.getElementById("ans"+i).innerHTML=''
    window.scrollTo(0,0);
    }
    document.write('<hr><form name="quiz">')
    var correct, answersString
    for (i = 0; i < questions.length; i++){
    answersString=''
    for (k = 1; k < questions[i].length; k+=2)
    answersString+='<input id="'+questions[i][(k+1)]+'" type="radio" unchecked name="q'+i+'"><label for="'+questions[i][(k+1)]+'">'+questions[i][k]+'</label><br>'
    for (j = 0; j < questions[i].length; j++){
    if (questions[i][j]=="right"+i)
    correct=questions[i][j-1]
    }
    with (document){
    write('Question '+(i+1)+':<br>')
    write(questions[i][0]+'<br>')
    write(answersString)
    if (allowPeeking)
    write('<input class="chkans" type="button" value="Check Answer" onclick="showAnswer(\'ans'+i+'\',\''+correct+'\')">&nbsp;<span id="ans'+i+'" class="chkans"></span><br>&nbsp;')
    write('<br>')
    }
    }
    with (document){
    write('<hr><br>')
    write('<input type="button" value="See Score" onclick="addup()">&nbsp;&nbsp;<span id="results"></span><br>&nbsp;<br>')
    if (allowDoOvers)
    write('<input type="button" value="Start Again" onclick="reset();clearR()">')
    write('</form>')
    }
    </script>
    
    </body></html>

  • #9
    New Coder
    Join Date
    Jul 2005
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Internet Explorer

    This code below is the closest one that can solve my problem:

    ======================

    Code:
    <head>
    <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] = "c";
    ans[2] = "b";
    ans[3] = "a";
    ans[4] = "c";
    ans[5] = "b";
    
    explainAnswer[1]="Answer 1 is";
    explainAnswer[2]="Answer 2 is";
    explainAnswer[3]="Answer 3 is";
    explainAnswer[4]="Answer 4 is";
    explainAnswer[5]="Answer 5 is";
    
    function Engine(question, answer) {
    yourAns[question]=answer;
    }
    
    function Score(){
    var answerText = "How did you do?\n------------------------------------\n";
    for(i=1;i<=5;i++){
    answerText=answerText+"\nQuestion :"+i+"\n";
    if(ans[i]!=yourAns[i]){
    answerText=answerText+"\nThe correct answer was "+ans[i]+"\n"+explainAnswer[i]+"\n";
    }
    else{
    answerText=answerText+" \nCorrect! \n";
    score++;
    }
    }
    
    answerText=answerText+"\n\nYour total score is : "+score+"\n";
    
    //now score the user
    answerText=answerText+"\nComment : ";
    if(score<=40){
    answerText=answerText+"You need to study";
    }
    if(score>=41 && score <=65){
    answerText=answerText+"You did ok, but you could have scored better";
    }
    if(score>=66 && score <=90){
    answerText=answerText+"Your study skills are good, almost perfect";
    }
    if(score>91){
    answerText=answerText+"Your Momma would be proud";
    }
    
    alert(answerText);
    
    }
    // End -->
    </script>
    
    </HEAD>
    
    
    <BODY>
    
    <DIV ALIGN="LEFT">
    <h1>Computer Test</h1>
    <b>"How much do you know about computers"</b>
    <hr>
    <FORM>
    <b>1. What is the difference between RAM and ROM?</b><br>
    <input type=radio name="q1" value="a" onClick="Engine(1, this.value)">a) There is no difference<br>
    <input type=radio name="q1" value="b" onClick="Engine(1, this.value)">b) RAM is volatile and ROM is non-volatile<br>
    <input type=radio name="q1" value="c" onClick="Engine(1, this.value)">c) RAM is non-permanent and ROM is permanent<br>
    <input type=radio name="q1" value="d" onClick="Engine(1, this.value)">d) RAM loses data when there is no electricity and ROM retains data when there is no electriciy.<p>
    
    <b>2. Question 2 here</b><br>
    <input type=radio name="q2" value="a" onClick="Engine(2, this.value)">a) Answer 2a here<br>
    <input type=radio name="q2" value="b" onClick="Engine(2, this.value)">b) Answer 2b here<br>
    <input type=radio name="q2" value="c" onClick="Engine(2, this.value)">c) Answer 2c here<br>
    <input type=radio name="q2" value="d" onClick="Engine(2, this.value)">d) Answer 2d here<p>
    
    <b>3. Question 3 here</b><br>
    <input type=radio name="q3" value="a" onClick="Engine(3, this.value)">a) Answer 3a here<br>
    <input type=radio name="q3" value="b" onClick="Engine(3, this.value)">b) Answer 3b here<br>
    <input type=radio name="q3" value="c" onClick="Engine(3, this.value)">c) Answer 3c here<br>
    <input type=radio name="q3" value="d" onClick="Engine(3, this.value)">d) Answer 3d here<p>
    
    <b>4. Question 4 here</b><br>
    <input type=radio name="q4" value="a" onClick="Engine(4, this.value)">a) Answer 4a here<br>
    <input type=radio name="q4" value="b" onClick="Engine(4, this.value)">b) Answer 4b here<br>
    <input type=radio name="q4" value="c" onClick="Engine(4, this.value)">c) Answer 4c here<br>
    <input type=radio name="q4" value="d" onClick="Engine(4, this.value)">d) Answer 4d here<p>
    
    <b>5. Question 5 here </b><br>
    <input type=radio name="q5" value="a" onClick="Engine(5, this.value)">a) Answer 5a here<br>
    <input type=radio name="q5" value="b" onClick="Engine(5, this.value)">b) Answer 5b here<br>
    <input type=radio name="q5" value="c" onClick="Engine(5, this.value)">c) Answer 5c here<br>
    <input type=radio name="q5" value="d" onClick="Engine(5, this.value)">d) Answer 5d here<p>
    
    <CENTER>
    <input type=button onClick="Score()" value="See how you scored!">
    </CENTER>
    </FORM>
    </DIV>
    but in my case, i need to explain all incorrect answers why they are incorrect, else they are right. Is there's any possibilty to make each questions to have 2 tries... then they will out of tries? This code is good almost fit and perfect to my 'project', what i need is a code where i can insert an explanation to "each" incorrect answers, comparing each of them to the right answer.. but the right answer always remain the same (for each questions. example in question 1. the correct answer remain the same).

    Thanks For this! Everything is perfect except or the explanation to each incorrect answers. Because of this i'm learning a little java scripts.

    Thanks a lot, again guys.
    Last edited by askman; 07-08-2005 at 05:13 AM.
    my email is: boyaskman@yahoo.com

  • #10
    New Coder
    Join Date
    Jul 2005
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Please i really need this, i'm running out of time. Don't need to make 2 tries per answer if necessary. All i need is for each radio button selected, once the "check score" was selected if incorrect there i can indicate in the popup massage why he is incorrect. For each questions. Because in my sample here, They only indicate if you are correct and the right answer. Please undrestand... i need it.

    Thanks
    my email is: boyaskman@yahoo.com

  • #11
    Regular Coder
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    375
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, I am working on it. I was wondering exactly how this is supposed to work though. I can make it congratulate the user if they are correct. If they are incorrect, what exactly is supposed to happen? Like for:

    Question:
    What part of the USA is New York State in?
    1) Mid-Atlantic Region
    2) South
    3) Western Coastal Area

    If they are right, we say Great, you are right. If they are wrong, does it have to say one thing if they picked South and another thing if they picked #3? Will there be more than one wrong answer? If so, do multiple advisories have to be available, one for each wrong choice or can it just be, for example for the above can it be:

    "No, New York State is not in that part of the USA it is in the Mid-Atlantic Region"

    ?

    Now, I just ran the code that you posted, it will never work for 50 questions as you mentioned before, the pop up box will be off the screen, being to large too read. Pop ups of this nature are not scrollable.

    Edit: Here is a link to the latest:
    New Quiz
    Last edited by jscheuer1; 07-08-2005 at 01:10 PM.

  • #12
    Regular Coder
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    375
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You seem like you are in such a hurry, odd you haven't gotten back to me. Anyways, this one will probably suit you, I hope. Normally I wouldn't put this out there without taking the time to clean it up a bit more, however you seem rushed, it works bug free (as far as I can tell) in FF1.0.4 and IE6 (my previous efforts were a bit more backwards compatible), so here you go:

    Code:
    <html>
    <head>
    <title>State Capitols Quiz</title>
    
    <style type="text/css">
    .chkans {
    margin:10px 10px -5px 0;
    } 
    
    span.chkans {
    position:relative;
    top:5px
    } 
    
    * html span.chkans {
    top:2px
    } 
    </style>
    
    </head>
    <body>
    <h1>State Capitols Quiz</h1>
    This page will tell what you know about state capitols.<br>
    <h2>Directions:</h2>
    Click on the correct answer.
    <span id="peek"></span><br><br>
    
    <script type="text/javascript">
    /*/////////////////////////////
    * Quiz Writing & Scoring Script
    * © 2005 John Davenport Scheuer
    * jscheuer1TAKEOUTCAPSFOREMAIL@comcast.net
    * permission to use granted
    * this credit must stay intact
    /////////////////////////////*/
    
    /*Set to 0 for no answers given away
      Set to 1 to allow peeking */
    var allowPeeking=1
    
    /*Set to 0 for no Starting Over without refresh
      Set to 1 to allow Easy Do Overs */
    var allowDoOvers=1
    
    /*Configure the text portions of the "You scored" statement.  Format is -
      scoreStr1 "number right" scoreStr2 "total number of questions" scoreStr3 "percentage score" scoreStr4
      Leave unchanged for default (You scored 6 out of 6 correct, 100%) */
    var scoreStr1='You scored<span style="color:blue;">'
    var scoreStr2='</span>out of<span style="color:blue;padding-left:.25ex;">'
    var scoreStr3='</span>correct,<span style="color:blue;">'
    var scoreStr4='</span>'
    
    questions=new Array();  // <<<< do not edit or remove this line!
    /*
      Set Question and Answers Arrays Below.
      Questions come first.  Then come the answer pairs:
      Follow the right answer with "right", all wrong ones with ""
      The final entry is the wrong answer string, to be shown when peeking if the answer is wrong.
      Example:
      questions[x]=["Do fish swim in the sea?", "Yes", "right", "No", "", "No, Fish really do swim in the sea"]
      single quotes (') must be double escaped (\\) ex: "That\\'s right!"
      double quotes (") must be named (&quot;) ex: "He referred to himself as &quot;King Louie&quot;"
    */
    questions[0]=["What is the capitol of Pennsylvania?", "Harrisburg", "right", "Oswego", "", "Philadelphia", "", "Denver", "", "That is not the capitol of Pennsylvania, Harrisburg is."]
    questions[1]=["What is the capitol of New Jersey?", "Princeton", "", "North Orange", "", "Trenton", "right", "Labrador", "", "That is not the capitol of New Jersey, Trenton is."]
    questions[2]=["What is the capitol of Montana?", "Billings", "", "Helena", "right", "Shelby", "", "Tabasco", "", "That is not the capitol of Montana, Helena is."]
    questions[3]=["What is the capitol of New York?", "Syracuse", "", "New York City", "", "Buffalo", "", "Albany", "right", "That is not the capitol of New York, Albany is."]
    questions[4]=["What is the capitol of Kansas?", "Atchison", "", "Topeka", "right", "Dodge City", "", "Manhattan", "", "That is not the capitol of Kansas, Topeka is."]
    questions[5]=["Are we having fun yet?", "Yes", "right", "No", "", "Aw c\\'mon, aren\\'t you having fun?"]
    questions[6]=["Do fish &quot;swim&quot; in the sea?", "Yes", "right", "No", "", "Fish really do &quot;swim&quot; in the sea."]
    
    ////////////////Stop Editing///////////////
    
    for (i = 0; i < questions.length; i++){
    for (j = 0; j < questions[i].length; j++){
    if (questions[i][j]=="")
    questions[i][j]=("w"+i)+j
    if (questions[i][j]=="right")
    questions[i][j]="right"+i
    }
    }
    var ie=document.all
    var moz=(document.getElementById&&!document.all)? 1 : 0
    var selq, report
    if (allowPeeking)
    ie? ie.peek.innerHTML='<br>Use the "Check Answer" buttons to see how you are doing.' : document.getElementById('peek').innerHTML='<br>Use the "Check Answer" buttons to see how you are doing.'
    function showAnswer(el,ans){
    ie? ie[el].innerHTML=selq+' is: '+ ans : document.getElementById(el).innerHTML=selq+' is: '+ ans
    }
    
    function getSelect(quest){
    selq='NO ANSWER,'
    selTest=document.getElementsByTagName('input')
    for (i = 0; i < selTest.length; i++)
    if (selTest[i].name==quest&&selTest[i].checked)
    selq=selTest[i].value+','
    }
    
    function addup()  {
    report='<input type="button" value="Return to Quiz" style="margin:0 0 10px 20px;" onclick="history.go(-1)"><br>'
    var q, right, statement, total=0
    quizQuests=new Array();
    for (i = 0; i < questions.length; i++)
    quizQuests[i]=0
    if (document.forms.quiz.q0['right0']){
    for (i = 0; i < questions.length; i++){
    q="q"+i
    right="right"+i
    if (document.forms.quiz[q][right].checked)
    quizQuests[i]=1
    //alert(report)
    }
    }
    else if (document.getElementById){
    for (i = 0; i < questions.length; i++){
    right="right"+i
    if (document.getElementById(right).checked)
    quizQuests[i]=1
    }
    }
    else
    return;
    var sq
    for (i = 0; i < questions.length; i++){
    total += quizQuests[i]
    //alert(quizQuests[i])
    q="q"+i
    selq='No Answer'
    selTest=document.getElementsByTagName('input')
    for (j = 0; j < selTest.length; j++)
    if (selTest[j].name==q&&selTest[j].checked)
    selq=selTest[j].value
    right="right"+i
    report+="Question"+(i+1)+":<br>"+questions[i][0]+"<br>Your Answer: "+selq+"<br>Correct Answer: "+document.getElementById(right).value+"<br>Points: "+quizQuests[i]+"<br><br>"
    }
    var prcnt=Math.round(total/questions.length*100)
    report+='Total Points: '+total+' out of &nbsp;'+ questions.length +', for a score of: ' +prcnt+'% &nbsp;'
    if (prcnt<=50)
    report+='Very Poor, Your study skills need improving.'
    else if (prcnt<=60)
    report+='Poor, spend more time studying.'
    else if (prcnt<=70)
    report+='Not too Bad, you need to study more often.'
    else if (prcnt<=80)
    report+='Good, with a little more work you could be really proud.'
    else if (prcnt<=90)
    report+='Very Good, you are still missing a few.'
    else if (prcnt<=100)
    report+='Excellent, which question(s) did you miss?'
    else if (prcnt==100)
    report+='Perfect, you should be really proud!'
    report+='<br><input type="button" value="Return to Quiz" style="margin:10px 0 0 20px;" onclick="history.go(-1)">'
    statement=scoreStr1 +' '+ total +' '+ scoreStr2 +' '+ questions.length +' '+ scoreStr3 +' '+ prcnt +'% '+ scoreStr4 +' &nbsp; &nbsp;<input type="button" value="See Details" onclick="document.write(report);document.close()">'
    ie? ie.results.innerHTML=statement : document.getElementById('results').innerHTML=statement
    }
    function clearR(){
    ie? ie.results.innerHTML='' : document.getElementById('results').innerHTML=''
    for (i = 0; i < questions.length; i++)
    if (allowPeeking)
    ie? ie["ans"+i].innerHTML='' : document.getElementById("ans"+i).innerHTML=''
    window.scrollTo(0,0);
    }
    document.write('<hr><form name="quiz">')
    var correct, incorrect, answersString
    for (i = 0; i < questions.length; i++){
    answersString=''
    for (k = 1; k < questions[i].length-1; k+=2)
    answersString+='<input id="'+questions[i][(k+1)]+'" type="radio" unchecked value="'+questions[i][k]+'" name="q'+i+'"><label for="'+questions[i][(k+1)]+'">'+questions[i][k]+'</label><br>'
    for (j = 0; j < questions[i].length; j++){
    if (questions[i][j]=="right"+i)
    correct=questions[i][j-1]
    incorrect=questions[i][questions[i].length-1]
    }
    with (document){
    write('Question '+(i+1)+':<br>')
    write(questions[i][0]+'<br>')
    write(answersString)
    if (allowPeeking)
    write('<input class="chkans" type="button" value="Check Answer" name="q'+i+'" onclick="getSelect(\'q'+i+'\');if (moz? document.getElementById(\'right'+i+'\').checked : ie? ie.right'+i+'.checked: 0==1) {showAnswer(\'ans'+i+'\',\' Correct!\')}else if (moz||ie) {showAnswer(\'ans'+i+'\',\'Incorrect! '+ incorrect +'\')}">&nbsp;<span id="ans'+i+'" class="chkans"></span><br>&nbsp;')
    write('<br>')
    }
    }
    with (document){
    write('<hr><br>')
    write('<input type="button" value="See Score" onclick="addup()">&nbsp;&nbsp;<span id="results"></span><br>&nbsp;<br>')
    if (allowDoOvers)
    write('<input type="button" value="Start Again" onclick="reset();clearR()">')
    write('</form>')
    }
    </script>
    
    </body></html>

  • #13
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    well if you already have a function to detect correct or incorrect answers..

    do you have a function that detects correct and incorrect answers already? From what I understand of your problem you do, and all you need is a way to add a button that shows how many are correct?

    Well if that's it, make sure you have a count to keep a tally of correct answers. Then somewhere in the html (where you want score to appear) insert something like this:

    Code:
    <form name="displayscore" onsubmit = "0">
    <input type="text" name="score" style="border:0 width: 350"/>
    </form>
    <form = action "">
    <input type = "button" name="b1" value="CheckScore" onClick="showScore()"/>
    </form>

    You can add changes to the syle of the input box to suit your needs widthwise/background color etc.

    Then you need a scoreDisplay() javascript function that would contain the value for the number of correct answers. Insert something like this into the HEAD of your html file.

    Code:
    <script language="javascript">
    var scorecount, totalquestions, display;
    showScore()
    {
          display = "Your Score is"+scorecount+"/"+totalquestions;
          document.displayscore.score.value = display;
    }
    </script>
    I hope that helps you , Good luck,

    Wallacer
    Last edited by wallacer; 07-08-2005 at 11:57 PM.

  • #14
    New Coder
    Join Date
    Jul 2005
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    this is too much guys! but i want to say THANK YOU very much! you are a great help. This one can actually do it..... i can use it already for my project... i can say 99% perfect. (The last code, the one with "see details") If possible can it be a 2 trial test for each question? example if they choose 1st incorrect... it will show why it is incorrect. now if they choose 2nd,then after the "check button" was clicked it will show why it is incorrect and he can never try again (for that question) a popup message will appear "Sorry you are out of tries"... if they refresh the page they can try again...that doesn't matter... but each question should be limited to 2 tries... BUT THANKS SO MUCH FOR THIS. that will do.

    because of this i'm now interested in learning java scripts.. i hope i can learn more so i can contribute to your forum in the future hehe
    my email is: boyaskman@yahoo.com

  • #15
    Regular Coder
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    375
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OK, I've got the two tries thing down. Actually, it and a lot of the features of this quiz are configurable as documented in the beginning part of the script. I've also upgraded the report so it looks nicer and takes up less screen real estate. I had to institute an onload event for Mozilla based browsers but, since this is or should generally be a stand alone page (not featured as a part of some other complex page except through a frame) that should be no problem. Here is the latest, v.5a2:

    Code:
    <html>
    <head>
    <title>State Capitols Quiz</title>
    
    <style type="text/css">
    .chkans {
    margin:10px 10px -5px 0;
    } 
    
    span.chkans {
    position:relative;
    top:5px
    } 
    
    * html span.chkans {
    top:2px
    } 
    </style>
    
    </head>
    <body>
    <h1>State Capitols Quiz</h1>
    This page will tell what you know about state capitols.<br>
    <h2>Directions:</h2>
    Click on the correct answer.
    <span id="peek"></span><br><br>
    
    <script type="text/javascript">
    /*/////////////////////////////
    * Quiz Writing & Scoring Script v.5a2
    * © 2005 John Davenport Scheuer
    * jscheuer1TAKEOUTCAPSFOREMAIL@comcast.net
    * permission to use granted
    * this credit must stay intact
    /////////////////////////////*/
    
    /*Set to number of peeks allowed per
      question. Set to (0) for no peeking */
    var tryLimit=2
    
    /*Set disable peeking style, (0) for
      disable 'Check Answer' button only,
      (1) for disable entire question. */
    var disablePeekStyle=1
    
    /*Set to 0 for no Starting Over without refresh
      Set to 1 to allow Easy Do Overs */
    var allowDoOvers=1
    
    /*Set Report Style */
    var reportStyle="background:lightblue;font-family:arial;font-weight:bold;font-size:.85em;color:navy;"
    
    /*Set Report Columns */
    var reportColumns=4
    
    /*Set number of Return from Report buttons, (0) for one return
      button at the bottom, (1) for added return button at top,
      good for long quizzes. */
    var dualReturn=1
    
    questions=new Array();  // <<<< do not edit or remove this line!
    /*
      Set Question and Answers Arrays Below.
      Questions come first.  Then come the answer pairs:
      Follow the right answer with "right", all wrong ones with ""
      The final entry is the wrong answer string*, to be shown when peeking if the answer is wrong.
      Example:
      questions[x]=["Do fish swim in the sea?", "Yes", "right", "No", "", "Fish really do swim in the sea"]
      single quotes (') must be double escaped (\\) ex: "That\\'s right!" *in the wrong answer string only*.
      double quotes (") must be named (&quot;) ex: "He referred to himself as &quot;King Louie&quot;"
    */
    questions[0]=["What is the capitol of Pennsylvania?", "Harrisburg", "right", "Oswego", "", "Philadelphia", "", "Denver", "", "That is not the capitol of Pennsylvania, Harrisburg is."]
    questions[1]=["What is the capitol of New Jersey?", "Princeton", "", "North Orange", "", "Trenton", "right", "Labrador", "", "That is not the capitol of New Jersey, Trenton is."]
    questions[2]=["What is the capitol of Montana?", "Billings", "", "Helena", "right", "Shelby", "", "Tabasco", "", "That is not the capitol of Montana, Helena is."]
    questions[3]=["What is the capitol of New York?", "Syracuse", "", "New York City", "", "Buffalo", "", "Albany", "right", "That is not the capitol of New York, Albany is."]
    questions[4]=["What is the capitol of Kansas?", "Atchison", "", "Topeka", "right", "Dodge City", "", "Manhattan", "", "That is not the capitol of Kansas, Topeka is."]
    questions[5]=["Are we having fun yet?", "Yes", "right", "No", "", "Aw c\\'mon, aren\\'t you having fun?"]
    questions[6]=["Do fish &quot;swim&quot; in the sea?", "Yes", "right", "No", "", "Fish really do &quot;swim&quot; in the sea."]
    
    /*Configure the text portions of the "You scored" statement.  Format is -
      scoreStr1 "number right" scoreStr2 "total number of questions" scoreStr3 "percentage score" scoreStr4
      Leave unchanged for default (You scored 6 out of 6 correct, 100%) */
    var scoreStr1='You scored<span style="color:blue;">'
    var scoreStr2='</span>out of<span style="color:blue;padding-left:.25ex;">'
    var scoreStr3='</span>correct,<span style="color:blue;">'
    var scoreStr4='</span>'
    
    ////////////////Stop Editing///////////////
    
    for (i = 0; i < questions.length; i++){
    eval('var tries'+i+'=0')
    for (j = 0; j < questions[i].length; j++){
    if (questions[i][j]=="")
    questions[i][j]=("w"+i)+j
    if (questions[i][j]=="right")
    questions[i][j]="right"+i
    }
    }
    var ie=document.all
    var moz=(document.getElementById&&!document.all)? 1 : 0
    var selq, report, allowPeeking
    tryLimit>0? allowPeeking=1 : allowPeeking=0
    document.getElementsByTagName? allowPeeking=allowPeeking : allowPeeking=0
    if (allowPeeking){
    var tryLimitV=['', '<u>one</u>', '<u>two</u>', '<u>three</u>', '<u>four</u>', '<u>five</u>', '<u>six</u>']
    tryLimitV[tryLimit]==undefined? tryLimitV[tryLimit]='<b>'+tryLimit+'</b>' : tryLimitV[tryLimit]=tryLimitV[tryLimit];
    ie? ie.peek.innerHTML='<br>Use the "Check Answer" buttons to see how you are doing.<br>Only '+tryLimitV[tryLimit]+' Check Answer\'s per question allowed.' : document.getElementById('peek').innerHTML='<br>Use the "Check Answer" buttons to see how you are doing.<br>Only '+tryLimitV[tryLimit]+' Check Answer\'s per question allowed.'
    }
    
    function showAnswer(el,ans,tryVar){
    if (tryVar!==undefined){
    if (eval('tries'+tryVar)>=tryLimit){
    alert ('Sorry, only '+tryLimit+' Check Answer\'s per question.')
    rbuts=document.getElementsByTagName('input')
    for (j = 0; j < rbuts.length; j++)
    if ((!disablePeekStyle)&&rbuts[j].name=='q'+tryVar&&rbuts[j].type!=='radio')
    rbuts[j].disabled=1
    else if (disablePeekStyle&&rbuts[j].name=='q'+tryVar)
    rbuts[j].disabled=1
    ie? ie[el].innerHTML='' : document.getElementById(el).innerHTML=''
    return;
    }
    eval ('tries'+tryVar+'++')
    }
    ie? ie[el].innerHTML=selq+' is: '+ ans : document.getElementById(el).innerHTML=selq+' is: '+ ans
    }
    
    function getSelect(quest){
    selq='NO ANSWER,'
    selTest=document.getElementsByTagName('input')
    for (i = 0; i < selTest.length; i++)
    if (selTest[i].name==quest&&selTest[i].checked)
    selq=selTest[i].value+','
    }
    
    function addup()  {
    var topReturn=''
    if (dualReturn)
    topReturn='<input type="button" value="Return to Quiz" style="margin:0 0 10px 20px;" onclick="history.go(-1)"><br>'
    report='<html><head><title>'+document.title+' - Your Results</title></head><body style="'+reportStyle+'"><h3>'+document.title+' - Your Results:</h3>'+topReturn+'<table align="center" cellpadding="10" style="'+reportStyle+'"><tr>'
    var q, right, statement, total=0
    quizQuests=new Array();
    for (i = 0; i < questions.length; i++)
    quizQuests[i]=0
    if (document.forms.quiz.q0['right0']){
    for (i = 0; i < questions.length; i++){
    q="q"+i
    right="right"+i
    if (document.forms.quiz[q][right].checked)
    quizQuests[i]=1
    }
    }
    else if (document.getElementById){
    for (i = 0; i < questions.length; i++){
    right="right"+i
    if (document.getElementById(right).checked)
    quizQuests[i]=1
    }
    }
    else
    return;
    for (i = 0; i < questions.length; i++)
    total += quizQuests[i]
    var seeDetails=''
    if (document.getElementsByTagName){
    for (i = 0; i < questions.length; i++){
    q="q"+i
    selq='No Answer'
    selTest=document.getElementsByTagName('input')
    for (j = 0; j < selTest.length; j++)
    if (selTest[j].name==q&&selTest[j].checked)
    selq=selTest[j].value
    right="right"+i
    if (i%reportColumns==0)
    report+='</tr><tr>'
    report+="<td>Question "+(i+1)+":<br>"+questions[i][0]+"<br>Your Answer: "+selq+"<br>Correct Answer: "+document.getElementById(right).value+"<br>Points: "+quizQuests[i]+"</td>"
    }
    var prcnt=Math.round(total/questions.length*100)
    report+='</tr></table><br>Total Points: '+total+' out of &nbsp;'+ questions.length +', for a score of: ' +prcnt+'% &nbsp; '
    if (prcnt<=50)
    report+='Very&nbsp;Poor.&nbsp; <nobr>Your study skills need improving.</nobr>'
    else if (prcnt<=60)
    report+='Poor.&nbsp; <nobr>Spend more time studying.</nobr>'
    else if (prcnt<=70)
    report+='Not&nbsp;Too&nbsp;Bad.&nbsp; <nobr>You need to study more often.</nobr>'
    else if (prcnt<=80)
    report+='Good.&nbsp; <nobr>With a little more work you could be really proud.</nobr>'
    else if (prcnt<=90)
    report+='Very&nbsp;Good!&nbsp; <nobr>You still missed one or more questions, study a little more.</nobr>'
    else if (prcnt<=99)
    report+='Excellent!&nbsp; <nobr>Which question(s) did you miss?</nobr>'
    else if (prcnt==100)
    report+='Perfect!&nbsp; <nobr>You should be really proud!</nobr>'
    report+='<br><br><input type="button" value="Return to Quiz" style="margin:10px 0 0 20px;" onclick="history.go(-1)"></body></html>'
    seeDetails='<input type="button" value="See Details" onclick="document.write(report);document.close()">'
    }
    statement=scoreStr1 +' '+ total +' '+ scoreStr2 +' '+ questions.length +' '+ scoreStr3 +' '+ prcnt +'% '+ scoreStr4 +' &nbsp; &nbsp;'+seeDetails
    ie? ie.results.innerHTML=statement : document.getElementById('results').innerHTML=statement
    }
    function clearR(){
    ie? ie.results.innerHTML='' : document.getElementById('results').innerHTML=''
    for (i = 0; i < questions.length; i++)
    if (allowPeeking){
    eval('tries'+i+'=0')
    ie? ie["ans"+i].innerHTML='' : document.getElementById("ans"+i).innerHTML=''
    inputs=document.getElementsByTagName('input')
    for (i = 0; i < inputs.length; i++)
    inputs[i].disabled=0
    }
    window.scrollTo(0,0);
    }
    document.write('<hr><form name="quiz">')
    var correct, incorrect, answersString
    for (i = 0; i < questions.length; i++){
    answersString=''
    for (k = 1; k < questions[i].length-1; k+=2){
    var peekRemove=(allowPeeking)? ' onmousedown="document.getElementById(\'ans'+i+'\').innerHTML=\'\'"' : ''
    answersString+='<input id="'+questions[i][(k+1)]+'" type="radio" value="'+questions[i][k]+'" name="q'+i+'"'+peekRemove+'><label for="'+questions[i][(k+1)]+'"'+peekRemove+'>'+questions[i][k]+'</label><br>'
    }
    for (j = 0; j < questions[i].length; j++){
    if (questions[i][j]=="right"+i)
    correct=questions[i][j-1]
    incorrect=questions[i][questions[i].length-1]
    }
    with (document){
    write('Question '+(i+1)+':<br>')
    write(questions[i][0]+'<br>')
    write(answersString)
    if (allowPeeking)
    write('<input class="chkans" type="button" value="Check Answer" name="q'+i+'" onclick="getSelect(\'q'+i+'\');if (moz? document.getElementById(\'right'+i+'\').checked : ie? ie.right'+i+'.checked: 0==1) {showAnswer(\'ans'+i+'\',\' Correct!\','+i+')}else if (moz||ie) {showAnswer(\'ans'+i+'\',\'Incorrect! '+ incorrect +'\','+i+')}">&nbsp;<span id="ans'+i+'" class="chkans"></span><br>&nbsp;')
    write('<br>')
    }
    }
    with (document){
    write('<hr><br>')
    write('<input type="button" value="See Score" onclick="addup()">&nbsp;&nbsp;<span id="results"></span><br>&nbsp;<br>')
    if (allowDoOvers)
    write('<input type="button" value="Start Again" onclick="reset();clearR()">')
    write('</form>')
    }
    if (moz&&document.getElementsByTagName&&allowPeeking){
    window.onload=function(){
    inputs=document.getElementsByTagName('input')
    for (i = 0; i < inputs.length; i++)
    inputs[i].disabled=0
    }
    }
    </script></body></html>
    Last edited by jscheuer1; 07-10-2005 at 09:44 AM.


  •  
    Page 1 of 5 123 ... LastLast

    LinkBacks (?)

    1. 05-08-2014, 10:29 AM
    2. 02-20-2014, 04:42 PM

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •