开发者

Dynamic radiobutton

This is aspx page which have datalist in datalist radio buttons are there. it is where radio button comning dynamicly i want to check all radio buttons are checked or not through javascript please help me

<asp:DataList  ID="TF_DataList" runat="server" RepeatDirection="Vertical" OnItemCreated="TF_Datalist_ItemCreated">
    <ItemTemplate>
        <table style="text-align:left;">
            <tr>
                <td valign="top" align="left" nowrap="nowrap">
                <asp:RadioButton ID="lbTrue" runat="server" GroupName="ans"  Text="T" onclick="Radcheck();"/>
                  <asp:RadioButton ID="lbFalse" runat="server" GroupName="ans" Text="F" onclick="Radcheck();"/>
</td>
                <td>&nbsp;&nbsp;</td>
                <td runat="server" id="AnswerContentTD" style="text-align: left">     
                    <asp:Label ID="lblAnswerText" runat="server" Text='<%# Eval("AnswerText")%>'></asp:Label>
                </td>
            </tr>  
        </table>
    </ItemTemplate>
     <ItemStyle HorizontalAlign="Left"></ItemStyle>
</asp:DataList&g开发者_JAVA技巧t;


Using Javascript

function ValidateDataListRadio() {
    var datalist = document.getElementById("<%= TF_DataList.ClientID %>");
    var items = datalist.getElementsByTagName('input');

    for (i = 0; i < items.length; i++) {
        if (items[i].type == "radio" && items[i].checked)) {
            return true;
        }
    }
    //alert("none selected");
    return false;
}

If you are using jQuery

Slight change in Markup. Added a CssClass to RadioButton

<asp:RadioButton ID="lbTrue" runat="server" 
            ClassName="radiobutton"
            GroupName="ans"
            Text="T" />

Code

function ValidateDataListRadio() {
    return $(".radiobutton").is(':checked').length;
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜