rgarimella
asked on
Multiple Radio Buttons Check
Hi Folks,
I have a series of radio button group with yes/no options.
I want to evaluate it to an array of correct answers, how do I do it?
var correctanswers = [1,0,1,0];
Where 1 is true or Yes is selected and 0 is false or No is selected
This has to be dynamic as sometimes there will be more than 4
Basically I want to match the arrays, if it is a correct match or not
Any help is appreciated
Thanks
RG
I have a series of radio button group with yes/no options.
I want to evaluate it to an array of correct answers, how do I do it?
var correctanswers = [1,0,1,0];
Where 1 is true or Yes is selected and 0 is false or No is selected
This has to be dynamic as sometimes there will be more than 4
Basically I want to match the arrays, if it is a correct match or not
Any help is appreciated
Thanks
RG
<form name="mcForm" method="post">
<table width="300" border="0" cellspacing="0" cellpadding="4">
<tr>
<td width="26" valign="top" id="radio1"> <input type="radio" name="radiobutton1" value="yes" accesskey="A" id="yes"></td>
<td width="18" valign="top" id="radio1"><input type="radio" name="radiobutton1" value="no" accesskey="B" id="no"></td>
<td width="556" valign="top" id="Text1"><font size="2" face="Arial, Helvetica, sans-serif"><label for="1">They compare different strategies</label></font></td>
</tr>
<tr>
<td width="26" valign="top" id="radio2"> <input type="radio" name="radiobutton2" value="yes" accesskey="C" id="yes"></td>
<td width="18" valign="top" id="radio2"><input type="radio" name="radiobutton2" value="no" accesskey="D" id="no"></td>
<td width="556" valign="top" id="Text2"><font size="2" face="Arial, Helvetica, sans-serif"><label for="2">They provide performance-based incentives
</label></font></td>
</tr>
<tr>
<td width="26" valign="top" id="radio3"> <input type="radio" name="radiobutton3" value="yes" accesskey="E" id="yes"></td>
<td width="18" valign="top" id="radio3"><input type="radio" name="radiobutton3" value="no" accesskey="F" id="no"></td>
<td width="556" valign="top" id="Text3"><font size="2" face="Arial, Helvetica, sans-serif"><label for="3">They provide data
</label></font></td>
</tr>
<tr>
<td width="26" valign="top" id="radio4"> <input type="radio" name="radiobutton" value="yes" accesskey="G" id="yes"></td>
<td width="18" valign="top" id="radio4"><input type="radio" name="radiobutton" value="no" accesskey="H" id="no"></td>
<td width="556" valign="top" id="Text4"><font size="2" face="Arial, Helvetica, sans-serif"><label for="4">They demonstrate the benefits
</label></font></td>
</tr>
<tr>
<td> </td>
<td></td>
<td> <div align="left">
<input type="button" value="Check Answer" onClick="checkAnswer(form)">
</div></td>
</tr>
</table>
</form>
ASKER
What does this line do
<INPUT TYPE="HIDDEN" VALUE="4" ID='TotalNumOfRDButton'>
The value will be dynamic, sometimes there will be 4 sets of radio buttons and then sometimes it is 5 or 6 etc.
<INPUT TYPE="HIDDEN" VALUE="4" ID='TotalNumOfRDButton'>
The value will be dynamic, sometimes there will be 4 sets of radio buttons and then sometimes it is 5 or 6 etc.
how are you going to generate them dynamically? by using Javascript ?
ASKER
No, the distractors are generated dynamically by ASP
so I dont know the number of distractors before hand
so I dont know the number of distractors before hand
is it gauranteed that ids would always be radio1 radio2 and so on ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry you need to replace line 11 with this code to get the result you (hopefully) want.
Kind regards,
Matthias Vance
Kind regards,
Matthias Vance
answers[answers.length] = (input.value.toLowerCase() == "yes" ? 1 : 0);
Open in new window