Hello everyone,
I am having a problem with the program below. I have isolated the problem
to the onclick event that is located throughout arrQuestions. The onclick
event refers to a function and passes it two parameters. For the life of me
I cannot figure out what the error is, but one occurs everytime I click a
&%*$&# radio button. Also, the function only alerts the user immediately
as to what question/answer they clicked. I am pretty much a rookie at
Javascript so I would appreciate any help that anyone might have time to
give.
<?xml version = "1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<title>Nascar Online Quiz</title>
<script type = "text/javascript">
<!--
var totalCorrect = 0;
var arrAnswers = new Array(10);
var arrCorrectAnswe rs = new Array("c", "d", "a", "c", "c", "d", "a", "c",
"b", "a");
var arrQuestions = new Array("<b>Who is the seven time Winston Cup Champion
who lost his life in the 2001 Daytona 500?</b><p>" +
"\n" +
"<input type='radio' name='question1 ' value='a'
onclick='funRec ordAnswer(1, this.value)'>Je ff Gordon<br />" +
"<input type='radio' name='question1 ' value='b'
onclick='funRec ordAnswer(1, this.value)'>Ri chard Petty<br />" +
"<input type='radio' name='question1 ' value='c'
onclick='funRec ordAnswer(1, this.value)'>Da le Earnhardt<br />" +
"<input type='radio' name='question1 ' value='d'
onclick='funRec ordAnswer(1, this.value)'>Fi reball Roberts<br />" +
"</p>",
"<b>Which Winston Cup driver is a two-time Busch Grand National
Series Champion and holds four straight wins at Talladega AL?</b><p>" +
"\n" +
"<input type='radio' name='question2 ' value='a'
onclick='funRec ordAnswer(2, this.value)'>Bo bby Labonte<br />" +
"<input type='radio' name='question2 ' value='b'
onclick='funRec ordAnswer(2, this.value)'>Ku rt Busch<br />" +
"<input type='radio' name='question2 ' value='c'
onclick='funRec ordAnswer(2, this.value)'>To ny Stewart<br />" +
"<input type='radio' name='question2 ' value='d'
onclick='funRec ordAnswer(2, this.value)'>Da le Earnhardt, Jr<br />" +
"</p>",
"<b>Which Winston Cup driver come from Las Vegas Nevada where he
used to stack groceries to pay for racing on weekends?</b><p>" +
"\n" +
"<input type='radio' name='question3 ' value='a'
onclick='funRec ordAnswer(3, this.value)'>Ku rt Busch<br />" +
"<input type='radio' name='question3 ' value='b'
onclick='funRec ordAnswer(3, this.value)'>Ke n Schrader<br />" +
"<input type='radio' name='question3 ' value='c'
onclick='funRec ordAnswer(3, this.value)'>Ma tt Kenseth<br />" +
"<input type='radio' name='question3 ' value='d'
onclick='funRec ordAnswer(3, this.value)'>Mi ke Skinner<br />" +
"</p>",
"<b>Which Winston cup driver is a four-time champion known as boy
wonder?</b><p>" +
"\n" +
"<input type='radio' name='question4 ' value='a'
onclick='funRec ordAnswer(4, this.value)'>Ry an Newman<br />" +
"<input type='radio' name='question4 ' value='b'
onclick='funRec ordAnswer(4, this.value)'>Ji mmie Johnson<br />" +
"<input type='radio' name='question4 ' value='c'
onclick='funRec ordAnswer(4, this.value)'>Je ff Gordon<br />" +
"<input type='radio' name='question4 ' value='d'
onclick='funRec ordAnswer(4, this.value)'>Ja mie McMurray<br />" +
"</p>",
"<b>Which Winston cup driver hails from Missouri and owns a
dirt-track outside of St. Louis?</b><p>" +
"\n" +
"<input type='radio' name='question5 ' value='a'
onclick='funRec ordAnswer(5, this.value)'>Ca sey Mears<br />" +
"<input type='radio' name='question5 ' value='b'
onclick='funRec ordAnswer(5, this.value)'>Jo e Nemechek<br />" +
"<input type='radio' name='question5 ' value='c'
onclick='funRec ordAnswer(5, this.value)'>Ke n Schrader<br />" +
"<input type='radio' name='question5 ' value='d'
onclick='funRec ordAnswer(5, this.value)'>Ji mmy Spencer<br />" +
"</p>",
"<b>Which driver has won more races in their career?</b><p>" +
"\n" +
"<input type='radio' name='question6 ' value='a'
onclick='funRec ordAnswer(6, this.value)'>Ru sty Wallace<br />" +
"<input type='radio' name='question6 ' value='b'
onclick='funRec ordAnswer(6, this.value)'>Ma rk Martin<br />" +
"<input type='radio' name='question6 ' value='c'
onclick='funRec ordAnswer(6, this.value)'>Da le Jarrett<br />" +
"<input type='radio' name='question6 ' value='d'
onclick='funRec ordAnswer(6, this.value)'>Je ff Gordon<br />" +
"</p>",
"<b>Which of these drivers is from Missouri?</b><p>" +
"\n" +
"<input type='radio' name='question7 ' value='a'
onclick='funRec ordAnswer(7, this.value)'>Ru sty Wallace<br />" +
"<input type='radio' name='question7 ' value='b'
onclick='funRec ordAnswer(7, this.value)'>Ma rk Martin<br />" +
"<input type='radio' name='question7 ' value='c'
onclick='funRec ordAnswer(7, this.value)'>Da le Jarrett<br />" +
"<input type='radio' name='question7 ' value='d'
onclick='funRec ordAnswer(7, this.value)'>Je ff Gordon<br />" +
"</p>",
"<b>Which driver was beaten by Dale Earnhardt for the 1990 Winston
Cup Championship?</b><p>" +
"\n" +
"<input type='radio' name='question8 ' value='a'
onclick='funRec ordAnswer(8, this.value)'>Ru sty Wallace<br />" +
"<input type='radio' name='question8 ' value='b'
onclick='funRec ordAnswer(8, this.value)'>Ne d Jarrett<br />" +
"<input type='radio' name='question8 ' value='c'
onclick='funRec ordAnswer(8, this.value)'>Ma rk Martin<br />" +
"<input type='radio' name='question8 ' value='d'
onclick='funRec ordAnswer(8, this.value)'>Da le Earnhardt, Jr<br />" +
"</p>",
"<b>Who currently drives the M&Ms sponsored car in Winston
Cup?</b><p>" +
"\n" +
"<input type='radio' name='question9 ' value='a'
onclick='funRec ordAnswer(9, this.value)'>Ke n Schrader<br />" +
"<input type='radio' name='question9 ' value='b'
onclick='funRec ordAnswer(9, this.value)'>El liott Sadler<br />" +
"<input type='radio' name='question9 ' value='c'
onclick='funRec ordAnswer(9, this.value)'>St erling Marlin<br />" +
"<input type='radio' name='question9 ' value='d'
onclick='funRec ordAnswer(9, this.value)'>Ri cky Craven<br />" +
"</p>",
"<b>Which of these drivers was a high school quarterback in
Nashville TN?</b><p>" +
"\n" +
"<input type='radio' name='question1 0' value='a'
onclick='funRec ordAnswer(10, this.value)'>St erling Marlin<br />" +
"<input type='radio' name='question1 0' value='b'
onclick='funRec ordAnswer(10, this.value)'>Jo hnny Benson<br />" +
"<input type='radio' name='question1 0'
value='c' onclick='funRec ordAnswer(10, this.value)'>Ke nny Wallace<br />" +
"<input type='radio' name='question1 0'
value='d' onclick='funRec ordAnswer(10, this.value)'>St eve Park<br />" +
"</p>"
);
function funPrintQuestio ns() {
var arrTest = new Array();
var j = 0;
var Test = false;
while ( j < 5) {
r_num = Math.floor(Math .random() * 10);
for ( var i = 0; i < arrTest.length; i++ ) {
if ( r_num == arrTest[i]) {
Test=true;
}
}
if ( Test == true ) {
Test = false;
continue;
}
else
{
arrTest[j] = r_num;
document.write( arrQuestions[r_num]);
j++;
}
} // end while
} // end function funPrintQuestio ns
function funInitialize() {
for ( var i = 0; i < arrAnswers.leng th; i++ )
arrAnswers[i] = "";
} // end funInitialize
function funRecordAnswer ( question, answer ) {
window.alert(qu estion);
window.alert(an swer);
return;
} // end funRecordAnswer
function funPrintButtons () {
document.write( "<input type = 'button' value='Grade Quiz'
onclick='funGra deQuiz()'>");
document.write( "<input type = 'button' value='Refresh Quiz'
onclick='locati on.reload()'>") ;
} // end funPrintButtons
function funGradeQuiz() {
for ( var i = 0; i < 10; i++ ) {
if ( arrAnswers[i] == arrCorrectAnswe rs[i] )
totalCorrect++;
}
window.alert("Y ou got " + totalCorrect + " correct!");
return;
} // end funGradeQuiz
// -->
</script>
</head>
<body onLoad = "funInitialize( ); funPrintQuestio ns(); funPrintButtons ();">
</body>
</html>
Thanks in advance,
Shock
I am having a problem with the program below. I have isolated the problem
to the onclick event that is located throughout arrQuestions. The onclick
event refers to a function and passes it two parameters. For the life of me
I cannot figure out what the error is, but one occurs everytime I click a
&%*$&# radio button. Also, the function only alerts the user immediately
as to what question/answer they clicked. I am pretty much a rookie at
Javascript so I would appreciate any help that anyone might have time to
give.
<?xml version = "1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<title>Nascar Online Quiz</title>
<script type = "text/javascript">
<!--
var totalCorrect = 0;
var arrAnswers = new Array(10);
var arrCorrectAnswe rs = new Array("c", "d", "a", "c", "c", "d", "a", "c",
"b", "a");
var arrQuestions = new Array("<b>Who is the seven time Winston Cup Champion
who lost his life in the 2001 Daytona 500?</b><p>" +
"\n" +
"<input type='radio' name='question1 ' value='a'
onclick='funRec ordAnswer(1, this.value)'>Je ff Gordon<br />" +
"<input type='radio' name='question1 ' value='b'
onclick='funRec ordAnswer(1, this.value)'>Ri chard Petty<br />" +
"<input type='radio' name='question1 ' value='c'
onclick='funRec ordAnswer(1, this.value)'>Da le Earnhardt<br />" +
"<input type='radio' name='question1 ' value='d'
onclick='funRec ordAnswer(1, this.value)'>Fi reball Roberts<br />" +
"</p>",
"<b>Which Winston Cup driver is a two-time Busch Grand National
Series Champion and holds four straight wins at Talladega AL?</b><p>" +
"\n" +
"<input type='radio' name='question2 ' value='a'
onclick='funRec ordAnswer(2, this.value)'>Bo bby Labonte<br />" +
"<input type='radio' name='question2 ' value='b'
onclick='funRec ordAnswer(2, this.value)'>Ku rt Busch<br />" +
"<input type='radio' name='question2 ' value='c'
onclick='funRec ordAnswer(2, this.value)'>To ny Stewart<br />" +
"<input type='radio' name='question2 ' value='d'
onclick='funRec ordAnswer(2, this.value)'>Da le Earnhardt, Jr<br />" +
"</p>",
"<b>Which Winston Cup driver come from Las Vegas Nevada where he
used to stack groceries to pay for racing on weekends?</b><p>" +
"\n" +
"<input type='radio' name='question3 ' value='a'
onclick='funRec ordAnswer(3, this.value)'>Ku rt Busch<br />" +
"<input type='radio' name='question3 ' value='b'
onclick='funRec ordAnswer(3, this.value)'>Ke n Schrader<br />" +
"<input type='radio' name='question3 ' value='c'
onclick='funRec ordAnswer(3, this.value)'>Ma tt Kenseth<br />" +
"<input type='radio' name='question3 ' value='d'
onclick='funRec ordAnswer(3, this.value)'>Mi ke Skinner<br />" +
"</p>",
"<b>Which Winston cup driver is a four-time champion known as boy
wonder?</b><p>" +
"\n" +
"<input type='radio' name='question4 ' value='a'
onclick='funRec ordAnswer(4, this.value)'>Ry an Newman<br />" +
"<input type='radio' name='question4 ' value='b'
onclick='funRec ordAnswer(4, this.value)'>Ji mmie Johnson<br />" +
"<input type='radio' name='question4 ' value='c'
onclick='funRec ordAnswer(4, this.value)'>Je ff Gordon<br />" +
"<input type='radio' name='question4 ' value='d'
onclick='funRec ordAnswer(4, this.value)'>Ja mie McMurray<br />" +
"</p>",
"<b>Which Winston cup driver hails from Missouri and owns a
dirt-track outside of St. Louis?</b><p>" +
"\n" +
"<input type='radio' name='question5 ' value='a'
onclick='funRec ordAnswer(5, this.value)'>Ca sey Mears<br />" +
"<input type='radio' name='question5 ' value='b'
onclick='funRec ordAnswer(5, this.value)'>Jo e Nemechek<br />" +
"<input type='radio' name='question5 ' value='c'
onclick='funRec ordAnswer(5, this.value)'>Ke n Schrader<br />" +
"<input type='radio' name='question5 ' value='d'
onclick='funRec ordAnswer(5, this.value)'>Ji mmy Spencer<br />" +
"</p>",
"<b>Which driver has won more races in their career?</b><p>" +
"\n" +
"<input type='radio' name='question6 ' value='a'
onclick='funRec ordAnswer(6, this.value)'>Ru sty Wallace<br />" +
"<input type='radio' name='question6 ' value='b'
onclick='funRec ordAnswer(6, this.value)'>Ma rk Martin<br />" +
"<input type='radio' name='question6 ' value='c'
onclick='funRec ordAnswer(6, this.value)'>Da le Jarrett<br />" +
"<input type='radio' name='question6 ' value='d'
onclick='funRec ordAnswer(6, this.value)'>Je ff Gordon<br />" +
"</p>",
"<b>Which of these drivers is from Missouri?</b><p>" +
"\n" +
"<input type='radio' name='question7 ' value='a'
onclick='funRec ordAnswer(7, this.value)'>Ru sty Wallace<br />" +
"<input type='radio' name='question7 ' value='b'
onclick='funRec ordAnswer(7, this.value)'>Ma rk Martin<br />" +
"<input type='radio' name='question7 ' value='c'
onclick='funRec ordAnswer(7, this.value)'>Da le Jarrett<br />" +
"<input type='radio' name='question7 ' value='d'
onclick='funRec ordAnswer(7, this.value)'>Je ff Gordon<br />" +
"</p>",
"<b>Which driver was beaten by Dale Earnhardt for the 1990 Winston
Cup Championship?</b><p>" +
"\n" +
"<input type='radio' name='question8 ' value='a'
onclick='funRec ordAnswer(8, this.value)'>Ru sty Wallace<br />" +
"<input type='radio' name='question8 ' value='b'
onclick='funRec ordAnswer(8, this.value)'>Ne d Jarrett<br />" +
"<input type='radio' name='question8 ' value='c'
onclick='funRec ordAnswer(8, this.value)'>Ma rk Martin<br />" +
"<input type='radio' name='question8 ' value='d'
onclick='funRec ordAnswer(8, this.value)'>Da le Earnhardt, Jr<br />" +
"</p>",
"<b>Who currently drives the M&Ms sponsored car in Winston
Cup?</b><p>" +
"\n" +
"<input type='radio' name='question9 ' value='a'
onclick='funRec ordAnswer(9, this.value)'>Ke n Schrader<br />" +
"<input type='radio' name='question9 ' value='b'
onclick='funRec ordAnswer(9, this.value)'>El liott Sadler<br />" +
"<input type='radio' name='question9 ' value='c'
onclick='funRec ordAnswer(9, this.value)'>St erling Marlin<br />" +
"<input type='radio' name='question9 ' value='d'
onclick='funRec ordAnswer(9, this.value)'>Ri cky Craven<br />" +
"</p>",
"<b>Which of these drivers was a high school quarterback in
Nashville TN?</b><p>" +
"\n" +
"<input type='radio' name='question1 0' value='a'
onclick='funRec ordAnswer(10, this.value)'>St erling Marlin<br />" +
"<input type='radio' name='question1 0' value='b'
onclick='funRec ordAnswer(10, this.value)'>Jo hnny Benson<br />" +
"<input type='radio' name='question1 0'
value='c' onclick='funRec ordAnswer(10, this.value)'>Ke nny Wallace<br />" +
"<input type='radio' name='question1 0'
value='d' onclick='funRec ordAnswer(10, this.value)'>St eve Park<br />" +
"</p>"
);
function funPrintQuestio ns() {
var arrTest = new Array();
var j = 0;
var Test = false;
while ( j < 5) {
r_num = Math.floor(Math .random() * 10);
for ( var i = 0; i < arrTest.length; i++ ) {
if ( r_num == arrTest[i]) {
Test=true;
}
}
if ( Test == true ) {
Test = false;
continue;
}
else
{
arrTest[j] = r_num;
document.write( arrQuestions[r_num]);
j++;
}
} // end while
} // end function funPrintQuestio ns
function funInitialize() {
for ( var i = 0; i < arrAnswers.leng th; i++ )
arrAnswers[i] = "";
} // end funInitialize
function funRecordAnswer ( question, answer ) {
window.alert(qu estion);
window.alert(an swer);
return;
} // end funRecordAnswer
function funPrintButtons () {
document.write( "<input type = 'button' value='Grade Quiz'
onclick='funGra deQuiz()'>");
document.write( "<input type = 'button' value='Refresh Quiz'
onclick='locati on.reload()'>") ;
} // end funPrintButtons
function funGradeQuiz() {
for ( var i = 0; i < 10; i++ ) {
if ( arrAnswers[i] == arrCorrectAnswe rs[i] )
totalCorrect++;
}
window.alert("Y ou got " + totalCorrect + " correct!");
return;
} // end funGradeQuiz
// -->
</script>
</head>
<body onLoad = "funInitialize( ); funPrintQuestio ns(); funPrintButtons ();">
</body>
</html>
Thanks in advance,
Shock
Comment