Hi Susan,
Try this.
<html>
<head>
<script language="javascript">
var correct=0;
function addQuiz(v){
if(v=='B') { correct++; }
}
function showScore()
{
alert("you got " + correct + " right!")
}
function resetVal()
{
document.myform.question1[0].value="A";
document.myform.question1[1].value="B";
document.myform.question2[0].value="B";
document.myform.question2[1].value="A";
correct=0;
}
</script>
<head>
<body bgcolor="yellow">
<h2>Test Quiz</h2><hr>
<h3>who invented javascript</h3>
<form name= "myform">
<input type="radio" name="question1" value="A" onChange="addQuiz(this.value);this.value='0';">Microsoft<BR>
<input type="radio" name="question1" value="B" onChange="addQuiz(this.value);this.value='0';">Netscape<BR>
<P>
<h3>Will you make SavageKid as your friend?</h3>
<input type="radio" name="question2" value="B" onChange="addQuiz(this.value);this.value='0';">Yes<BR>
<input type="radio" name="question2" value="A" onChange="addQuiz(this.value);this.value='0';">No<BR>
<input type="button" value="score" onclick="showScore()">
<input type="reset" value="reset" onClick="resetVal()" >
</form>
</body>
</html>
And the explanation:
Look at the onChange event in the radio buttons.I declared the 'correct' variable outside the addQuiz function so that it is global.Now the onchange event will pass the value of the radio button to the addQuiz function as a parameter.If the parameter value is equal to 'B' the value of 'correct' is incremented.When you click the score button the showScore function is called which alerts the score.In the reset button check out the onClick event which call the resetVal() function which resets the old values of the radio buttons.Hope you understood.
C'ya
Savage
