javascript - ShowHide table row based on radio buttons - Stack Overflow

I have a set of four radio buttons that represent four different conditions (Good, Improving, Worsening

I have a set of four radio buttons that represent four different conditions (Good, Improving, Worsening, Poor). Selecting "worsening" or "poor" should unhide a table row with a textarea to explain why the condition is not good. Selecting "good" or "improving" should hide the table row. I've tried adding a class to the two that unhide the table row, but only one of the buttons is working (worsening). I have a feeling I need an or clause in there somewhere to pickup both buttons, but I've tried many variations and I'm just not ing up with it. Appreciate any help for this noob.

Here is what I have:

<tr>
     <td>
      Customer Sentiment:
    </td>
    <td colspan="3">
    <div id="sentiment">
        <input class="xhide" type="radio" id="Good" value="1"   name="sentimentID" <cfif sentimentID eq 1>checked</cfif> /><label for="Good">Good</label>
        <input class="xhide" type="radio" id="Improving" value="2" name="sentimentID" <cfif sentimentID eq 2>checked</cfif> /><label for="Improving">Improving</label>
        <input class="xshow" type="radio" id="Worsening" value="3" name="sentimentID" <cfif sentimentID eq 3>checked</cfif> /><label for="Worsening">Worsening</label>
        <input class="xshow" type="radio" id="Poor" value="4"   name="sentimentID" <cfif sentimentID eq 4>checked</cfif> /><label for="Poor">Poor</label>
    </div>
    </td>
</tr>                        

<tr class="rnotes"">
    <td valign="top">Sentiment Notes:</td>
    <td colspan="3">
        <cfoutput>
        <textarea   name="sentimentNotes"
                    cols="100"
                    rows="4">#sentimentNotes#</textarea>
        </cfoutput>
    </td>
</tr>

Script:

$(document).ready(function() 
{
    $(".rnotes").hide();

    $(':radio').change(function(){
    var isChecked=$('.xshow').prop('checked');
    $('.rnotes').toggle(isChecked);
    });
});

========================================================================

I have a set of four radio buttons that represent four different conditions (Good, Improving, Worsening, Poor). Selecting "worsening" or "poor" should unhide a table row with a textarea to explain why the condition is not good. Selecting "good" or "improving" should hide the table row. I've tried adding a class to the two that unhide the table row, but only one of the buttons is working (worsening). I have a feeling I need an or clause in there somewhere to pickup both buttons, but I've tried many variations and I'm just not ing up with it. Appreciate any help for this noob.

Here is what I have:

<tr>
     <td>
      Customer Sentiment:
    </td>
    <td colspan="3">
    <div id="sentiment">
        <input class="xhide" type="radio" id="Good" value="1"   name="sentimentID" <cfif sentimentID eq 1>checked</cfif> /><label for="Good">Good</label>
        <input class="xhide" type="radio" id="Improving" value="2" name="sentimentID" <cfif sentimentID eq 2>checked</cfif> /><label for="Improving">Improving</label>
        <input class="xshow" type="radio" id="Worsening" value="3" name="sentimentID" <cfif sentimentID eq 3>checked</cfif> /><label for="Worsening">Worsening</label>
        <input class="xshow" type="radio" id="Poor" value="4"   name="sentimentID" <cfif sentimentID eq 4>checked</cfif> /><label for="Poor">Poor</label>
    </div>
    </td>
</tr>                        

<tr class="rnotes"">
    <td valign="top">Sentiment Notes:</td>
    <td colspan="3">
        <cfoutput>
        <textarea   name="sentimentNotes"
                    cols="100"
                    rows="4">#sentimentNotes#</textarea>
        </cfoutput>
    </td>
</tr>

Script:

$(document).ready(function() 
{
    $(".rnotes").hide();

    $(':radio').change(function(){
    var isChecked=$('.xshow').prop('checked');
    $('.rnotes').toggle(isChecked);
    });
});

========================================================================

Share Improve this question asked Apr 23, 2013 at 17:55 akaboboakabobo 391 silver badge4 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

Here is the script:

$(document).ready(function() 
{
    $(".rnotes").hide();

    $('input[type=radio]').change(function(){
        var isChecked = $(this).prop('checked');
        var isShow = $(this).hasClass('xshow');
        $(".rnotes").toggle(isChecked && isShow);
    });
});

Working fiddle: http://jsfiddle/LnyJZ/5/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744852674a4597220.html

相关推荐

  • javascript - ShowHide table row based on radio buttons - Stack Overflow

    I have a set of four radio buttons that represent four different conditions (Good, Improving, Worsening

    2天前
    70

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信