Creating a quiz on dreamweaver

  • Halim_akiki
  • Born
  • Born
  • Halim_akiki
  • Posts: 1

Post 3+ Months Ago

Hi. i need to do a quiz on dreamweaver using radio buttons to get the answers. i'm having a problem in releasing radio buttons after checking one radio and moving to a next question using a "Next>>" button the same radio checked in the first question is checked in the second question. can anyone help me with this ? thank you. This is the whole exercise :
Code: [ Select ]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Quiz Easy</title>

<script type="text/javascript">

var questions=["Lebanon's capital:","France's capital:","England's capital:"];
var answers=[["beyrouth","sayda","tripoli"],
       ["souchaux","paris","lyon"],
             ["manchester","cambridge","london"]];
var trueAnswers=[0,1,2];
var chosenAnswers=[-1, -1, -1];
var cur=0;
var grade=0;

function start(){

    cur = 0;
    showQuestion();
}


function showQuestion(){
    quest.innerText = (cur+1) + ") "+questions[cur];
    rep1.innerText = answers[cur][0];
    rep2.innerText = answers[cur][1];
    rep3.innerText = answers[cur][2];
}

function goNext(){
    if (cur < questions.length-1){
        cur++;
        showQuestion();
    }
}

function goPrevious(){
    if (cur > 0 ){
        cur--;
        showQuestion();
    }
}

function goFirst(){
   cur = 0;
     showQuestion();
}

function goLast(){
   cur = questions.length-1;
     showQuestion ();
}

/*function getAnswers ()
{
    for (i=0, i<answers.length, i++)
    {
         for(j=0, j<answers[i].length, j++)
         {
              if(answers[i][j].checked)
                 chosenAnswers[i] = answers[i][j];
             else
                 chosenAnswers[i] = -1;
         }
     }
}*/

/*function getAnswer() {
    chosenAnswers = "";
    len = answers.length;

    for (i = 0; i <len; i++) {
        if (answers[i].checked) {
            chosenAnswers = answers[i];
            return chosenAnswers;
        }
        else{
            return -1;
        }
    }
}*/

function checkAnswer(){
    grade = 0;
    for (i=0; i<trueAnswers.length; i++){
        if (trueAnswers[i] == chosenAnswers[i]){
            grade = grade + 1;
        }
    }
    
}

function score(){
  alert("You had a score of " + grade + " points!")
}

function clearRB(buttonGroup)
{
 for (i=0; i < buttonGroup.length; i++) {

  if (buttonGroup[i].checked == true) { // if a button in group is checked,
     buttonGroup[i].checked = false; // uncheck it
   }
  
 } 
}

</script>
</head>

<body onload="start()">

<form name="clearIt">
<h1 id="quest"> </h1>
<p> <input type="radio" name="radioA" id="radio1"/> <span id="rep1"> </span> </p>
<p> <input type="radio" name="radioA" id="radio2"/> <span id="rep2"> </span> </p>
<p> <input type="radio" name="radioA" id="radio3"/> <span id="rep3"> </span> </p>
<p> <input type="button" name="clear" value="clear" onclick="clearRB(document.clearIt.radioA)" /> </p>
</form>

<p><input type="button" value="First |<<" onclick="goFirst()"/>
<input type="button" value="Previous <" onclick="goPrevious()"/>
<input type="button" value="Next >" onclick="goNext()"/>
<input type="button" value="Last >>|" onclick="goLast()"/>
<input type="button" value="Submit Answers" onclick="checkAnswer()"/>
<input type="button" value="Show Result" onclick="score()"/></p>



</body>
</html>
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>Quiz Easy</title>
  5. <script type="text/javascript">
  6. var questions=["Lebanon's capital:","France's capital:","England's capital:"];
  7. var answers=[["beyrouth","sayda","tripoli"],
  8.        ["souchaux","paris","lyon"],
  9.              ["manchester","cambridge","london"]];
  10. var trueAnswers=[0,1,2];
  11. var chosenAnswers=[-1, -1, -1];
  12. var cur=0;
  13. var grade=0;
  14. function start(){
  15.     cur = 0;
  16.     showQuestion();
  17. }
  18. function showQuestion(){
  19.     quest.innerText = (cur+1) + ") "+questions[cur];
  20.     rep1.innerText = answers[cur][0];
  21.     rep2.innerText = answers[cur][1];
  22.     rep3.innerText = answers[cur][2];
  23. }
  24. function goNext(){
  25.     if (cur < questions.length-1){
  26.         cur++;
  27.         showQuestion();
  28.     }
  29. }
  30. function goPrevious(){
  31.     if (cur > 0 ){
  32.         cur--;
  33.         showQuestion();
  34.     }
  35. }
  36. function goFirst(){
  37.    cur = 0;
  38.      showQuestion();
  39. }
  40. function goLast(){
  41.    cur = questions.length-1;
  42.      showQuestion ();
  43. }
  44. /*function getAnswers ()
  45. {
  46.     for (i=0, i<answers.length, i++)
  47.     {
  48.          for(j=0, j<answers[i].length, j++)
  49.          {
  50.               if(answers[i][j].checked)
  51.                  chosenAnswers[i] = answers[i][j];
  52.              else
  53.                  chosenAnswers[i] = -1;
  54.          }
  55.      }
  56. }*/
  57. /*function getAnswer() {
  58.     chosenAnswers = "";
  59.     len = answers.length;
  60.     for (i = 0; i <len; i++) {
  61.         if (answers[i].checked) {
  62.             chosenAnswers = answers[i];
  63.             return chosenAnswers;
  64.         }
  65.         else{
  66.             return -1;
  67.         }
  68.     }
  69. }*/
  70. function checkAnswer(){
  71.     grade = 0;
  72.     for (i=0; i<trueAnswers.length; i++){
  73.         if (trueAnswers[i] == chosenAnswers[i]){
  74.             grade = grade + 1;
  75.         }
  76.     }
  77.     
  78. }
  79. function score(){
  80.   alert("You had a score of " + grade + " points!")
  81. }
  82. function clearRB(buttonGroup)
  83. {
  84.  for (i=0; i < buttonGroup.length; i++) {
  85.   if (buttonGroup[i].checked == true) { // if a button in group is checked,
  86.      buttonGroup[i].checked = false; // uncheck it
  87.    }
  88.   
  89.  } 
  90. }
  91. </script>
  92. </head>
  93. <body onload="start()">
  94. <form name="clearIt">
  95. <h1 id="quest"> </h1>
  96. <p> <input type="radio" name="radioA" id="radio1"/> <span id="rep1"> </span> </p>
  97. <p> <input type="radio" name="radioA" id="radio2"/> <span id="rep2"> </span> </p>
  98. <p> <input type="radio" name="radioA" id="radio3"/> <span id="rep3"> </span> </p>
  99. <p> <input type="button" name="clear" value="clear" onclick="clearRB(document.clearIt.radioA)" /> </p>
  100. </form>
  101. <p><input type="button" value="First |<<" onclick="goFirst()"/>
  102. <input type="button" value="Previous <" onclick="goPrevious()"/>
  103. <input type="button" value="Next >" onclick="goNext()"/>
  104. <input type="button" value="Last >>|" onclick="goLast()"/>
  105. <input type="button" value="Submit Answers" onclick="checkAnswer()"/>
  106. <input type="button" value="Show Result" onclick="score()"/></p>
  107. </body>
  108. </html>
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

Post Information

  • Total Posts in this topic: 1 post
  • Users browsing this forum: No registered users and 71 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.