Creating a quiz on dreamweaver
- Halim_akiki
- Born


- Joined: Jul 10, 2011
- Posts: 1
- Status: Offline
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>
<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>
- <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>
- Anonymous
- Bot


- Joined: 25 Feb 2008
- Posts: ?
- Loc: Ozzuland
- Status: Online
July 10th, 2011, 6:49 am
Page 1 of 1
To Reply to this topic you need to LOGIN or REGISTER. It is free.
Post Information
- Total Posts in this topic: 1 post
- Users browsing this forum: No registered users and 176 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
