Hi guys,
I’m writing ( trying to ) a Javascript Quiz which dynamicaly shows the questions one at a time on the same page. This much I have working..
What I’m having problems with is that the user can click on their selected answer text ( on a radio button ) to go to the next question. But, if they click the radio button itself. It does nothing.
I assume it has something to do with the label?
But I need that as it’s used to dynamicaly change the text for each question.
Can anyone help?
The Form bit.
[CODE]
<FORM name=formquiz class=”style1″>
<div align=”center”></div>
<p id=QuesNo>Question: x of 20. </p>
<TABLE width=600 border=1 align=”center” cellPadding=1 cellSpacing=1 bgcolor=”#CCCCCC”>
<TBODY>
<TR>
<TD width=”600″ height=”106″ valign=”top” bgcolor=”#FFFFFF”><div align=”center”>
<div align=”center”><strong><P id=Question>Here is the question to be asked. </P></strong></div>
<div>
<INPUT name=r1 type=radio id=r0 value=0>
<label for=”r0″ id=”Answer0″ onClick=”Check(0)” >Answer 0</label><br>
</div>
<div>
<INPUT type=radio value=1 name=r1 id=r1>
<label for=”r1″ id=”Answer1″ onClick=”Check(1)”>Answer 0</label><br>
</div>
<div>
<INPUT type=radio value=2 name=r1 id=r2>
<label for=”r2″ id=”Answer2″ onClick=”Check(2)”>Answer 0</label><br>
</div>
<div>
<INPUT type=radio value=3 name=r1 id=r3>
<label for=”r3″ id=”Answer3″ onClick=”Check(3)”>Answer 0</label><br>
</div>
<br>
<br>
</div></TD>
</TR>
</TBODY>
</TABLE>
<br>
</FORM>
The Javascript bit.
[CODE]
<script language=’javascript’ type=’text/javascript’>
var QuestionNumber=0;
function CreateArray (NumOfRows, NumOfCols )
// Function to create a 2D Array.
{
var k= new Array (NumOfRows );
for (i=0; i<k.length; ++i )
k[i]=new Array (NumOfCols);
return k;
}
function Check(pressed)
{
var buttonValue = 9;
QArray[QuestionNumber][6]=pressed;
QuestionNumber++;
DisplayQuestion(QuestionNumber);
}
P.s. Sorry about the variable inconsistencies.
Thanks for your help.
Jason.