“You have not selected X” does not hide after a radio button has been selected.
script:
$('input').live('change', function ()
{
if($('debt:radio:checked')) {
$('.debt1').html('<span style="display:none"></span>');}
if($('assets:radio:checked')) {
$('.assets1').html('<span style="display:none"></span>');}
if($('kids:radio:checked')) {
$('.kids1').html('<span style="display:none"></span>');}
});
html:
Debt: <br />
<input name="debt" type="radio" value="0" />
<input name="debt" type="radio" value="-1" />
<input name="debt" type="radio" value="-2" /><br />
Kids:<br />
<input name="kids" type="radio" value="0" />
<input name="kids" type="radio" value="1" />
<input name="kids" type="radio" value="3" /><br />
Assets:<br />
<input name="assets" type="radio" value="4" />
<input name="assets" type="radio" value="5" />
<input name="assets" type="radio" value="6" /><br />
<br />
<span class="debt1">You have not selected debt</span><br />
<span class="kids1">You have not selected kids</span><br />
<span class="assets1">You have not selected assets</span><br />
Sample here: http://jsfiddle.net/ZJpRj/1/
Working example here: http://jsfiddle.net/ZJpRj/6/
First, you didn’t select jquery in your fiddle.
Then, your if statement needs to change a lot.
Should be something more like this:
Your code has a few issues. First, the selector
debt:radio:checked. Just puttingdeptwould match an element like<dept></dept>, not an input with the name dept. And 2nd,if($("..."))will always return true, because jquery always returns an object. You want to check if that object contains any elements, which is why I uselength.