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.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Storing data in an array

    Good day everyone. I downloaded this code from javascriptkit.com. okay the applications has 10 questions. How can i split the questions into 10 meaning into 10 html pages using next button instead of leaving all the 10 questions on just a page and ensures that answers are well calculated. below is the code any help?

    RESULT.HTM
    Code:
    <html>
    
    <head>
    <title>Instant Quiz Results</title>
    </head>
    
    <body bgcolor="#FFFFFF">
    
    <p align="center"><strong><font face="Arial">
    
    <script src="quizconfig.js">
    </script>
    
    <big>Instant Quiz Results</big></font></strong></p>
    <div align="center"><center>
    
    <table border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="100%"><form method="POST" name="result"><table border="0" width="100%" cellpadding="0" height="116">
            <tr>
              <td height="25" bgcolor="#D3FFA8"><strong><font face="Arial"># of questions you got right:</font></strong></td>
              <td height="25"><p><input type="text" name="p" size="24"></td>
            </tr>
            <tr>
              <td height="17" bgcolor="#D3FFA8"><strong><font face="Arial">The questions you got wrong:</font></strong></td>
              <td height="17"><p><textarea name="T2" rows="3" cols="24" wrap="virtual"></textarea></td>
            </tr>
            <tr>
              <td height="25" bgcolor="#D3FFA8"><strong><font face="Arial">Grade in percentage:</font></strong></td>
              <td height="25"><input type="text" name="q" size="8"></td>
            </tr>
          </table>
        </form>
        </td>
      </tr>
    </table>
    </center></div>
    
    <form method="POST"><div
      align="center"><center><p>
    
    <script>
    var wrong=0
    for (e=0;e<=2;e++)
    document.result[e].value=""
    
    var results=document.cookie.split(";")
    for (n=0;n<=results.length-1;n++){
    if (results[n].charAt(1)=='q')
    parse=n
    
    }
    
    var incorrect=results[parse].split("=")
    incorrect=incorrect[1].split("/")
    if (incorrect[incorrect.length-1]=='b')
    incorrect=""
    document.result[0].value=totalquestions-incorrect.length+" out of "+totalquestions
    document.result[2].value=(totalquestions-incorrect.length)/totalquestions*100+"%"
    for (temp=0;temp<incorrect.length;temp++)
    document.result[1].value+=incorrect[temp]+", "
    
    
    </script>
    
    <input type="button" value="Take the quiz again" name="B1"
      onClick="history.go(-1)"> <input type="button" value="View solution" name="B2"
      onClick="showsolution()"></p>
      </center></div>
    </form>
    
    <p id="footnote" align="center"><font face="arial" size="-1">Quiz script provided by<br>
    <a href="http://www.javascriptkit.com">JavaScriptKit.com</a></font></p>
    </body>
    </html>
    POPQUIZ.HTML
    Code:
    <html>
    
    <head>
    <title>JavaScriptKit.com Multiple Choice Quiz Script</title>
    
    <style>
    .qheader{
    font:bold 14px Arial;
    }
    
    .qselections{
    font:normal 13px Arial;
    }
    </style>
    
    <script src="quizconfig.js">
    </script>
    
    <script>
    
    /***********************************************
    * JavaScriptKit.com Multiple Choice Quiz Script (http://www.javascriptkit.com)
    * Copyright 2003 JavaScript Kit- http://www.javascriptkit.com
    * This notice and footnote must stay intact for use
    * Visit JavaScript Kit (http://www.javascriptkit.com/) for full source code
    ***********************************************/
    
    var actualchoices=new Array()
    document.cookie="ready=yes"
    </script>
    
    </head>
    
    <body bgcolor="#FFFFFF">
    
    <!--Comments on configuring quiz script-->
    <!--Change the questions below any way you want, but make note of the following:-->
    <!--1) Perserve the <FORM> tags -->
    <!--2a) Inside each radio button, use the VALUE attribute to denote each question's choices: "a", "b", "c" etc.-->
    <!--2b) Inside each radio button, use the NAME attribute to denote which question the button belongs to ("question1", "question2" etc-->
    <!--3) Script supports unlmited # of questions. Be sure to edit .js file to enter corresponding solutions-->
    
    <p align="center">
    
    <form method="POST" name="myquiz">
    
    <font face="Arial"><big><big>General Knowledge Quiz</big></big></font></p>
    
    <div class="qheader">
    1) What is the difference between a jungle and a rain forest?</div>
    <div class="qselections">
    <input type="radio" value="a" name="question1">a) No difference. Simply two different ways in referring to the same thing.<br>
    <input type="radio" value="b" name="question1">b) A jungle in general receives less rain than a rain forest.<br>
    <input type="radio" value="c" name="question1">c) A jungle refers to the thickest area of a rain forest<br>
    <input type="radio" value="d" name="question1">d) A jungle and a rain forest each contain their own group of distinct plants and animals.<br>
    </div>
    
    <br>
    
    <div class="qheader">
    2) What is the world's most common religion?</div>
    <div class="qselections">
    <input type="radio" value="a" name="question2">a) Christianity<br>
    <input type="radio" value="b" name="question2">b) Buddhism<br>
    <input type="radio" value="c" name="question2">c) Hinduism<br>
    <input type="radio" value="d" name="question2">d) Muslim<br>
    </div>
    
    <br>
    
    <div class="qheader">
    3) Which city ranks as the world's most populous city (2002)?</div>
    <div class="qselections">
    <input type="radio" value="a" name="question3">a) New York (US)<br>
    <input type="radio" value="b" name="question3">b) Mexico City (Mexico)<br>
    <input type="radio" value="c" name="question3">c) Tokyo (Japan)<br>
    <input type="radio" value="d" name="question3">d) Shanghai (China)<br>
    </div>
    
    <br>
    
    <div class="qheader">
    4) What is the second largest country (in size) in the world?</div>
    <div class="qselections">
    <input type="radio" value="a" name="question4">a) USA<br>
    <input type="radio" value="b" name="question4">b) China<br>
    <input type="radio" value="c" name="question4">c) Canada<br>
    <input type="radio" value="d" name="question4">d) Russia<br>
    </div>
    
    <br>
    
    <div class="qheader">
    5) As of January 2003, how much is Microsoft Chairman Bill Gates's net worth?</div>
    <div class="qselections">
    <input type="radio" value="a" name="question5">a) 10 million US<br>
    <input type="radio" value="b" name="question5">b) 10 billion US<br>
    <input type="radio" value="c" name="question5">c) 35 billion US<br>
    <input type="radio" value="d" name="question5">d) 50 billion US<br>
    </div>
    
    <br>
    
    <div class="qheader">
    6) Which country below is not one of the members of the UN security council (Jan 2003)?</div>
    <div class="qselections">
    <input type="radio" value="a" name="question6">a) USA<br>
    <input type="radio" value="b" name="question6">b) China<br>
    <input type="radio" value="c" name="question6">c) Germany<br>
    <input type="radio" value="d" name="question6">d) France<br>
    </div>
    
    <br>
    
    <div class="qheader">
    7) The longest river in the world is:</div>
    <div class="qselections">
    <input type="radio" value="a" name="question7">a) Amazon (Brazil)<br>
    <input type="radio" value="b" name="question7">b) Nile (Egypt)<br>
    <input type="radio" value="c" name="question7">c) Yangtze (China)<br>
    <input type="radio" value="d" name="question7">d) Congo (Zaire)<br>
    </div>
    
    <br>
    
    <div class="qheader">
    8) Which software firm is the second largest in the world, after Microsoft?</div>
    <div class="qselections">
    <input type="radio" value="a" name="question8">a) Netscape<br>
    
    <input type="radio" value="b" name="question8">b) Oracle<br>
    <input type="radio" value="c" name="question8">c) Lotus<br>
    <input type="radio" value="d" name="question8">d) Norton<br>
    </div>
    
    <br>
    
    <div class="qheader">
    9) What's the world's most widely spoken language?</div>
    <div class="qselections">
    <input type="radio" value="a" name="question9">a) English<br>
    <input type="radio" value="b" name="question9">b) Spanish<br>
    <input type="radio" value="c" name="question9">c) Mandarin<br>
    <input type="radio" value="d" name="question9">d) French<br>
    </div>
    
    <br>
    
    <div class="qheader">
    10) Which continent is host to the most countries in the world?</div>
    <div class="qselections">
    <input type="radio" value="a" name="question10">a) Asia<br>
    <input type="radio" value="b" name="question10">b) Africa<br>
    <input type="radio" value="c" name="question10">c) Europe<br>
    </div>
    
    </form>
    
    <form>
    <div align="center">
    <input type="button" value="Grade Me!" name="B1" onClick="gradeit()"> <input type="button" value="Reset" name="B2" onClick="document.myquiz.reset()"></div>
    </form>
    
    <p id="footnote" align="center"><font face="arial" size="-1">Quiz script provided by<br>
    <a href="http://www.javascriptkit.com">JavaScriptKit.com</a></font></p>
    </body>
    </html>

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,550
    Thanks
    78
    Thanked 4,382 Times in 4,347 Posts
    Quite frankly, you would throw that code out and start over.

    A much simpler answer would be to, instead, as each question is answered you hide it and then un-hide the next one.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,017
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Quote Originally Posted by Old Pedant View Post
    Quite frankly, you would throw that code out and start over.

    A much simpler answer would be to, instead, as each question is answered you hide it and then un-hide the next one.
    Use the search feature of this forum - you will find several quiz scripts.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

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