いくつかのチェックボックスがあり、各グループには選択可能なコンポーネントが 1 つしかありません。チェックボックスの例を以下に示します。
<label class="checkbox inline">
<input type="checkbox" id="question1option1" name="question1options" value="correct" onclick="SingleSelect('question1option',this)"> 1
</label>
<label class="checkbox inline">
<input type="checkbox" id="question1option2" name="question1options" value="wrong" onclick="SingleSelect('question1option',this)"> 2
</label>
<label class="checkbox inline">
<input type="checkbox" id="question1option3" name="question1options" value="wrong" onclick="SingleSelect('question1option',this)"> 3
</label>
<label class="checkbox inline">
<input type="checkbox" id="question2option1" name="question2options" value="correct" onclick="SingleSelect('question2option',this)"> 1
</label>
<label class="checkbox inline">
<input type="checkbox" id="question2option2" name="question2options" value="wrong" onclick="SingleSelect('question2option',this)"> 2
</label>
<label class="checkbox inline">
<input type="checkbox" id="question2option3" name="question2options" value="wrong" onclick="SingleSelect('question2option',this)"> 3
</label>
私は、ラジオボタングループ(以下)を渡すことによってどのラジオボタンが選択されているかを引き出すJavaScript関数を持っています.チェックされたチェックボックス(各「グループ」に1つだけ)同様の方法をお願いします?
function getRadioValue (theRadioGroup)
{
for (var i = 0; i < document.getElementsByName(theRadioGroup).length; i++)
{
if (document.getElementsByName(theRadioGroup)[i].checked)
{
return document.getElementsByName(theRadioGroup)[i].value;
}
}
}
前もって感謝します。