ラジオボタンのグループのハンドラーを登録する必要があります。私はJQueryを使用しており、その.changeメソッドがこれを実現することを望んでいます。しかし、私は望ましい行動を経験していません。
これが私が書いたサンプルスニペットです。残念ながら、「radioValueChanged」は初期ロード時にのみ呼び出されます。true / falseのいずれかを選択しても、ハンドラーはトリガーされません。
<html>
<script src="jquery-1.4.2.min.js" type="text/javascript"></script>
<form id="myForm">
<div id="Question1Wrapper">
<div>
<input type="radio" name="controlQuestion" id="valueFalse" value="0" />
<label for="valueFalse">
False</label>
</div>
<div>
<input type="radio" name="controlQuestion" id="valueTrue" value="1" />
<label for="valueTrue">
True</label>
</div>
</div>
<div id="Question2Wrapper">
<div>
<label for="optionalTextBox">
This is only visible when the above is true</label>
<input type="text" name="optionalTextBox" id="optionalTextBox" value="" />
</div>
</div>
<script type="text/javascript">
jQuery(document).ready(function ()
{
$("#controlQuestion").change(radioValueChanged('controlQuestion'));
})
function radioValueChanged(radioName)
{
radioValue = $('input[name=' + radioName + ']:checked', '#myForm').val();
alert(radioValue);
if(radioValue == 'undefined' || radioValue == "0")
{
$('#Question2Wrapper:visible').hide();
}
else
{
$('#Question2Wrapper:visible').show();
}
}
</script>
</form>