开发者

Attach a .Change event to a Radiobutton list. (Values bound at run time)

How can i attach a .change event to a radiobuttonlist which has its values bound at runtime

rbSecurity.dataSource = Data();
rbSecurity.dataBind();

I want to hide a dropdownlist (ddlContact) based on certain selection in the rbSecurity

I tried this but doesn't work:

$("#<%=rbSecurity.Client开发者_开发问答ID%> input[name*='Security']").change(function () {
            if ($("input[@name=GroupName]:checked").val() != 'Value1') {
                $('#<%=ddlApprovers.ClientID %>').hide();
            }
            else {
                $('#<%=ddlApprovers.ClientID %>').show();
            }
        }
    });

Thanks in advance


You could attach a change handler to every radio button in your RadioButtonList that takes action only when the radio button is checked. For instance:

Control declaration:

<asp:RadioButtonList ID="rbSecurity" runat="server" />

jQuery:

$("#<%=rbSecurity.ClientID%> input:radio").change(function() {
    if (this.checked) {
        if (this.value == "Value1") {
            $("#<%=ddlContact.ClientID %>").show();
        }
        else {
            $("#<%=ddlContact.ClientID %>").hide();
        }
    }
}).filter(":checked").change();

Notice in the jQuery snippet I also suggest you fire an initial change event for the radio button that is checked on page load.

In the code's if block, you could test this.value to see if it is part of a valid set of values and call .show() for a particular selector, and if it is not, .hide() that selector instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜