I have a radio button with two possible values yes or no.
I would like when user press yes a div will be appeared and when no
hide the div.
My code is but it does not work:
<script type="text/javascript">
$(document).ready(function() {
$("div.desc").hide();
$("input[name$='pain']").click(function() {
var test = $(this).val();
$("div.desc").hide();
$("#" + test).show();
});
});
</script>
<div id="fieldsetInner">
<fieldset class="rightInner">
<legend>pain</legend>
<label for="pain" class="label2">do you feel pain ; </label>
<input name="pain" type="radio" value="yes" id="yes" checked="checked"/> Yes
<input name="pain" type="radio" value="no"/> No
<div id="yes" class="desc">
<label for="pain-feature1-morph" class="label2">Morph : </label>
</div>
</div>
Thanks in advance
Mr.T.K :
I hope this will help you\n\n <input name=\"pain\" type=\"radio\" value=\"yes\" id=\"yes\"/> Yes\n <input name=\"pain\" type=\"radio\" value=\"no\" id=\"no\" /> No\n\n\n $('input:radio[name=pain]').click(function() {\n if ($('#yes').attr('checked')) {\n $('.desc').show();\n } else if ($('#no').attr('checked')) {\n $('.desc').hide();\n }\n\n });\n",
2011-11-14T12:42:43
Manuel van Rijn :
you could do\n\n$(\"input#yes\").click(function() {\n $(\"div.desc\").show();\n});\n$(\"input#no\").click(function() {\n $(\"div.desc\").show();\n});\n",
2011-11-14T12:31:56