tags:

views:

65

answers:

3

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>
A: 

It could be the selector; can you try changing

$("#<%=ChkTest.ClientID %>").click(function() {

To:

$('.ToggleYesNo').click(function() {

If that doesn't help, can you comment with the output you get from:

alert($("#<%=ChkTest.ClientID %>"));
alert($('.ToggleYesNo'));
Russ C
it outputs an `output` objectI have also attached the HTML OUTPUT of the part see. I could call statically call the two checkbox, but it is not that flexible
Starx
A: 

try

$(document).ready(function() {
    $("#ChkTest").click(function() {
        value = $(this).find(':checked').val();
        if(value=='1') {
            $('#atextbox').attr('disabled','');
         }
         else {
            $('#atextbox').attr('disabled','disabled');
         }           

    });
});

EDIT based on UPDATED by the OP

$(document).ready(function() {
    $("#ChkTest :checkbox").click(function() {
        value = $(this).next().text().toLowerCase();
        if(value=='yes') {
            $('#atextbox').attr('disabled','');
         }
         else {
            $('#atextbox').attr('disabled','disabled');
         }           

    });
});
Reigel
this didn't work
Starx
please see edit...
Reigel
I also solved, please find my solution and comment on this
Starx
+1  A: 

Ok, I solved it

my jQuery function is

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

This totally solved it

Starx
the value of `.attr('checked')` is not always `true` if checked... when attribute `checked` holds any value (except `null`, `false`) it's state in view is always checked... for example, `checked="checked"`
Reigel
Then how to overcome this
Starx
you can `value = $(this).is(':checked');` returns true or false, if the checkbox is checked or not...
Reigel