无法访问radiobutton列表的选定值

时间:2013-02-13 12:03:06

标签: javascript .net

我有一个单选按钮列表

 <asp:RadioButtonList CssClass="radioLable" ID="rbListPointsCat" runat="server"   RepeatDirection="Horizontal"
                    AutoPostBack="true" OnSelectedIndexChanged="rbListPointsCat_SelectedIndexChanged">
                    <asp:ListItem runat="server" Value="Yes" />
                    <asp:ListItem runat="server" Value="No" />
                </asp:RadioButtonList>

我正在使用以下JS函数

          function CheckValue(sender, args) {

        var rblist = document.getElementById('<% =rbListPointsCat.ClientID%>');
        for (var x = 0; x < rblist.cells.length; x++) {
            if (rblist.cells[x].checked) {
                var Choice = (rblist.cells[x].innerText);
                alert(Choice);
            }
        }


        if (Choice=="No") {
            if (txtRemarks.value == "") {
                args.IsValid = false;
            }
            else {
                args.IsValid = true;
            }
        }
        else {
            args.IsValid = true;
        }
    }

但无法获得已检查的值。这将是未定义的。 请告诉我哪里出错了?

1 个答案:

答案 0 :(得分:0)

按名称呼叫

      function CheckValue(sender, args) {

    var rblist = document.getElementByName('<% =rbListPointsCat.ClientID%>');
    for (var x = 0; x < rblist.cells.length; x++) {
        if (rblist.cells[x].checked) {
            var Choice = (rblist.cells[x].innerText);
            alert(Choice);
        }
    }


    if (Choice=="No") {
        if (txtRemarks.value == "") {
            args.IsValid = false;
        }
        else {
            args.IsValid = true;
        }
    }
    else {
        args.IsValid = true;
    }
}