需要在Datalist中实现javascript valiadation

时间:2017-06-27 13:36:04

标签: javascript c# jquery asp.net datalist

嗨我的页面布局如下图所示

enter image description here

我想要的是点击大小调整复选框内部单选按钮获取自动选中,点击石头重置内部单选按钮列表进行自动检查。

我的HTML代码看起来像

<asp:DataList ID="dtbindjewellery" runat="server"  OnItemDataBound="dtbindjewellery_ItemDataBound" Width="100%">
            <ItemTemplate>
                             <div class="col-md-12 col-sm-12 col-xs-12 jewelerymain">
                                <asp:CheckBox ID="Servicechkbox" runat="server" Text='<%#Eval("ServiceName")%>' />
                                <asp:HiddenField ID="hdserviceid" runat="server" Value='<%#Eval("ServiceId")%>' />                                    
                            </div>
                 <%-- Sizing Radiobutton--%>                                 
                        <div id="divsizing" runat="server" class="col-md-12 col-sm-12 col-xs-12 subservices" visible="false">
                            <asp:RadioButton ID="rdsizing1" runat="server" GroupName="ringsize" />                                
                            <asp:DropDownList ID="ddselectSize" runat="server"></asp:DropDownList>
                            <br />
                            <asp:RadioButton ID="rdsizing2" runat="server" GroupName="ringsize" />                                
                            <asp:TextBox ID="txtsize" runat="server" CssClass="txtNumericUpDownExtender"></asp:TextBox>

                        </div>
                       <%-- Stone resetting Radiobutton--%>                                 
                        <asp:RadioButtonList ID="radiosub" runat="server"></asp:RadioButtonList>                   
            </ItemTemplate>
        </asp:DataList>

这里有2个独特的单选按钮和石头重置有单选按钮列表。

我根据不同的ID绑定它,复选框和无线电的ID在数据列表中得到更改。

如何在javascript中点击复选框点击验证?

1 个答案:

答案 0 :(得分:1)

使用如下。

 function Specialinstruction() {
        var datalist = document.getElementById("<%=dtbindjewellery.ClientID%>");
        var count = datalist.rows.length;

        for (i = 0; i < count; i++) {
            var chkid = document.getElementById('ContentPlaceHolder1_JewelleryServices_dtbindjewellery_Servicechkbox_' + i);
            //var checkboxid = document.getElementById(id);
            if (chkid.checked == true) {
                // alert("hello");
                var hdservice = document.getElementById('ContentPlaceHolder1_JewelleryServices_dtbindjewellery_hdserviceid_' + i);
                var value = hdservice.value;

                if (value == 3) {
                    var rdsizing1 = document.getElementById('ContentPlaceHolder1_JewelleryServices_dtbindjewellery_rdsizing1_' + i);
                    var rdsizing2 = document.getElementById('ContentPlaceHolder1_JewelleryServices_dtbindjewellery_rdsizing2_' + i);
                    if (rdsizing1.checked == false && rdsizing2.checked == false)
                    { rdsizing1.checked = true; }
                }
}
}

   <asp:CheckBox ID="Servicechkbox" CssClass="cb" onClick="Specialinstruction();" runat="server" Text='<%#Eval("ServiceName")%>' />