jquery get radiobuttonlist by name dynamically

Posted by Cindy on Stack Overflow See other posts from Stack Overflow or by Cindy
Published on 2010-06-11T14:00:00Z Indexed on 2010/06/11 14:32 UTC
Read the original article Hit count: 237

Filed under:

I have two radiobuttonlist and one checkboxlist on the page. Ideally based on the checkbox selected value, I want to enable/disable corresponding radibuttonlist with jquery function.

But some how $("input[name*=" + columnName + "]") always return null. It can not find the radiobuttonlist by its name?

    $(function() {
        function checkBoxClicked() {

            var isChecked = $(this).is(":checked");
            var columnName = "rblColumn" + $(this).parent().attr("alt");

            if (isChecked) {
                $("input[name*=" + columnName + "]").removeAttr("disabled");
            } else {
                $("input[name*=" + columnName + "]").attr("disabled", "disabled");

                $("input[name*=" + columnName + "] input").each(function() {
                    $(this).attr("checked", "")
                });

            }

        }

        //intercept any check box click event inside the #list Div
        $(":checkbox").click(checkBoxClicked);
    });




<asp:Panel ID="TestPanel" runat="server">
<asp:CheckBoxList ID = "chkColumn" runat="server" RepeatDirection="Horizontal">
    <asp:ListItem id = "Column1" runat="server" Text="Column 1" Value="1" alt="1" class="HeadColumn" />
    <asp:ListItem id = "Column2" runat="server" Text="Column 2" Value="2" alt="2" class="HeadColumn"/>
</asp:CheckBoxList>

<table>
    <tr>
        <td>
            <asp:RadioButtonList ID = "rblColumn1" runat="server" RepeatDirection="Vertical" disabled="disabled">
                <asp:ListItem id="liColumn1p" runat="server" />
                <asp:ListItem id="liColumn1n" runat="server" />
            </asp:RadioButtonList>
        </td>
        <td>
            <asp:RadioButtonList ID = "rblColumn2" runat="server" RepeatDirection="Vertical" disabled="disabled">
                <asp:ListItem id="liColumn2p" runat="server" />
                <asp:ListItem id="liColumn2n" runat="server" />
            </asp:RadioButtonList>
        </td>
    </tr>
</table>
</asp:Panel>

source:

<div id="TestPanel">

<table id="chkColumn" border="0">
        <tr>
            <td><span id="Column1" alt="1" class="HeadColumn"><input id="chkColumn_0" type="checkbox" name="chkColumn$0" /><label for="chkColumn_0">Column 1</label></span></td><td><span id="Column2" alt="2" class="HeadColumn"><input id="chkColumn_1" type="checkbox" name="chkColumn$1" /><label for="chkColumn_1">Column 2</label></span></td>
        </tr>
    </table>

<table>
    <tr>
        <td>
            <table id="rblColumn1" class="myRadioButtonList" disabled="disabled" border="0">
        <tr>
            <td><span id="liColumn1p"><input id="rblColumn1_0" type="radio" name="rblColumn1" value="" /></span></td>
        </tr><tr>
            <td><span id="liColumn1n"><input id="rblColumn1_1" type="radio" name="rblColumn1" value="" /></span></td>
        </tr>
    </table>
        </td>
        <td>
            <table id="rblColumn2" class="myRadioButtonList" disabled="disabled" border="0">
        <tr>
            <td><span id="liColumn2p"><input id="rblColumn2_0" type="radio" name="rblColumn2" value="" /></span></td>
        </tr><tr>
            <td><span id="liColumn2n"><input id="rblColumn2_1" type="radio" name="rblColumn2" value="" /></span></td>
        </tr>
    </table>
        </td>
    </tr>
</table>

</div>

© Stack Overflow or respective owner

Related posts about jQuery