Click to See Complete Forum and Search --> : How to Reset Radio Buttons?


Malvina
08-01-2003, 11:19 PM
I am attempting to implement a java script quiz. Have it working but am unable to determine how to reset the radio buttons so that someone can clear the form and try again. I am able to return the score to zero but haven't a clue how to reset the buttons. I'm obviously a novice and would appreciate help.

I'm using a script from the site and modifying as necessary. Here is the script and also the reset "onclick" code.

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

var score = 0;
ans[1] = "b";
ans[2] = "b";
ans[3] = "a";
ans[4] = "b";
ans[5] = "a";

explainAnswer[1]="False";
explainAnswer[2]="False";
explainAnswer[3]="True";
explainAnswer[4]="False";
explainAnswer[5]="True";


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+"The correct answer was "+ans[i]+"\n"+explainAnswer[i]+"\n";
}
else{
answerText=answerText+"Correct! \n";
score++;
}
}

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

//now score the user
answerText=answerText+"\nComment : ";
if(score<=0){
answerText=answerText+"Contact FedReady";
}
if(score>=1 && score <=2){
answerText=answerText+"Contact FedReady";
}
if(score>=3 && score <=3){
answerText=answerText+"Contact FedReady";
}
if(score>=4){
answerText=answerText+"Congratulations";
}

alert(answerText);

}

function Reset(){
score = 0;
}
// End -->
</script>
<input type=button onClick="Reset()" value="Start Over" >

AdamGundry
08-02-2003, 05:32 AM
Couldn't you just use an <input type="reset"> instead?

Adam

Malvina
08-02-2003, 07:35 AM
I initially used reset and the radio buttons were cleared but the score was not cleared. The question then is - if I use reset how do I zero out the score?

Fang
08-02-2003, 08:04 AM
Reset radio button to off:

document.myform.radio_1.checked="";

Reset radio button to on:

document.myform.radio_1.checked="true";

AdamGundry
08-02-2003, 08:59 AM
Reset buttons still have an onclick event handler, so you can do this:

<input type="reset" onclick="score = 0;" value="Start Over">

Adam