How to fetch the value of selected checkbox inside a checkboxList?

Posted by Starx on Stack Overflow See other posts from Stack Overflow or by Starx
Published on 2010-06-03T08:07:34Z Indexed on 2010/06/03 8:34 UTC
Read the original article Hit count: 172

Filed under:
|
|

I want to know the selected value of the markup below. So that I can disabled a textbox, if one of the checkbox is selected.

    <asp:CheckBoxList ID="ChkTest" runat="server" RepeatDirection="Horizontal" CssClass="toggleYesNo">
        <asp:ListItem Value="1">Yes</asp:ListItem>
        <asp:ListItem Value="0">No</asp:ListItem>
    </asp:CheckBoxList>

I tried using this function it doesnot seem to work

$(document).ready(function() {
    $("#<%=ChkTest.ClientID %>").click(function() {
        value = $(this).val();
        if(value=='1') {
            $('#atextbox').attr('disabled','');
         }
         else {
            $('#atextbox').attr('disabled','disabled');
         }           

    });
});

I also track the output HTML but the id the CheckBoxList the assigned to a table instead.

UPDATED

<table id="ChkTest" class="toggleYesNo" border="0">
    <tr>
        <td><input id="ChkTest_0" type="checkbox" name="ChkTest$0" /><label for="ChkTest_0">Yes</label></td><td><input id="ChkTest_1" type="checkbox" name="ChkTest$1" /><label for="ChkTest_1">No</label></td>
    </tr>
</table>

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET