Нужна помощь, чтобы создать цикл для моего кода проверки в ASP.NET
В моем примере кода я проверяю 2 переключателя одновременно. Я не хочу использовать список переключателей. Я хотел бы проверить это только на стороне клиента. Прямо сейчас я пишу функцию для каждого набора кнопок. Есть только 2 набора кнопок, но на моем реальном сайте у меня их гораздо больше. Я использую этот код в качестве примера, чтобы сделать его простым. Я хотел бы использовать цикл вместо того, чтобы писать функцию для каждого набора кнопок. не мог бы кто-нибудь, пожалуйста, но этот код внутри цикла jQuery для каждого набора кнопок.
Спасибо за любую помощь
Что я уже пробовал:
<%@ Page Title="" Language="C#" MasterPageFile="Site.master" AutoEventWireup="true" CodeFile="PickAllPool_2.aspx.cs" Inherits="PickAllPool_2" %> <asp:Content ID="HeadContent" ContentPlaceHolderID="head" Runat="Server"> <script> function openModal() { $('#myModal').modal({ show: true }); } </script> </asp:Content> <asp:Content ID="BodyContent" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <div class="poolContainer"> <!---------- Pick All Games ----------> <div class="row box row-eq-height"> <div class="col-lg-2 col-md-1 visible-lg visible-md awayBg">Left Col</div> <div class="col-lg-8 col-md-10 col-sm-12 col-xs-12 box"> <div class="row"><br /><br /> <div class="poolHeader col-lg-12 col-md-12 col-sm-12 col-xs-12"> <img src="Images/poolHeader.png" /> </div> </div><br /> <asp:Repeater ID="myRepeater" runat="server"> <ItemTemplate> <!---------- Game 1 ----------> <asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="* Select a Team for this Game" ForeColor="#ff0000" SetFocusOnError="true" /> <div class="row box"> <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <label class="teamBtn"> <div class="teamContainer"> Game 1<span class="teamBgLeft"><img class="helmit" src="Images/team_logos/<%# Eval("T2_logoAway") %>" alt="" /> <span class="teamText"><%#Eval("GameAway_1")%><h5>(<asp:Label ID="lblGame1AwayWins" runat="server" />-<asp:Label ID="lblGame1AwayLost" runat="server" />) - Away</h5></span></span> <asp:RadioButton ID="AwayGame_1" GroupName="Game_1" Text='<%#Eval("GameAway_1")%>' Font-Size="0" runat="server" TabIndex="12" CssClass="hidden" /> </div> </label> </div> <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <label class="teamBtn"> <div class="teamContainer"> <asp:RadioButton ID="HomeGame_1" GroupName="Game_1" Text='<%#Eval("GameHome_1")%>' Font-Size="0" runat="server" TabIndex="13" CssClass="hidden" /> <span class="teamBgRight"><span class="teamText"><%#Eval("GameHome_1")%><h5>(<asp:Label ID="lblGame1HomeWins" runat="server" />-<asp:Label ID="lblGame1HomeLost" runat="server" />) - Home</h5></span> <img class="helmit" src="Images/team_logos/<%# Eval("T1_logoHome") %>" alt="" /> </span> </div> </label> </div> </div> <!---------- Game 2 ----------> <asp:CustomValidator ID="CustomValidator2" runat="server" ErrorMessage="* Select a Team for this Game" ForeColor="#ff0000" SetFocusOnError="true" /> <div class="row box"> <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <label class="teamBtn"> <div class="teamContainer"> <span class="teamBgLeft"><img class="helmit" src="Images/team_logos/<%# Eval("T4_logoAway") %>" alt="" /> <span class="teamText"><%#Eval("GameAway_2")%><h5>(<asp:Label ID="lblGame2AwayWins" runat="server" />-<asp:Label ID="lblGame2AwayLost" runat="server" />) - away</h5></span></span> <asp:RadioButton ID="AwayGame_2" GroupName="Game_2" Text='<%#Eval("GameAway_2")%>' Font-Size="0" runat="server" TabIndex="14" CssClass="hidden" /> </div> </label> </div> <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <label class="teamBtn"> <div class="teamContainer"> <asp:RadioButton ID="HomeGame_2" GroupName="Game_2" Text='<%#Eval("GameHome_2")%>' Font-Size="0" runat="server" TabIndex="15" CssClass="hidden" /> <span class="teamBgRight"><span class="teamText"><%#Eval("GameHome_2")%><h5>(<asp:Label ID="lblGame2HomeWins" runat="server" />-<asp:Label ID="lblGame2HomeLost" runat="server" />) - home</h5></span> <img class="helmit" src="Images/team_logos/<%# Eval("T3_logoHome") %>" alt="" /></span> </div> </label> </div> </div> <!---------- Total Points ----------> <div class="row row-eq-height"> <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <asp:RequiredFieldValidator ID="RequiredFieldValidator99" runat="server" ErrorMessage="Total Points is required" ControlToValidate="txtTotalPointsUser" ForeColor="#ff0000" SetFocusOnError="True" CssClass="errMsg" Display="Dynamic" /> <asp:RegularExpressionValidator ID="RegularExpressionValidator99" runat="server" ErrorMessage="Enter numbers only" ControlToValidate="txtTotalPointsUser" ForeColor="#ff0000" ValidationExpression="[0-9]{1,50}" SetFocusOnError="True" CssClass="errMsg" Display="Dynamic" /> <label class="totalPointsText" for="tieBreaker">Total Points: </label> </div> <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <asp:TextBox ID="txtTotalPointsUser" CssClass="form-control" Type="Integer" runat="server" TabIndex="34" Width="125px" placeholder="Required" /> </div> </div> <asp:Label ID="lblWeek" Text='<%#Eval("Week")%>' runat="server" Visible="false" /> <!---------- Confirm Button ----------> <div class="row box"> <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 text-center" ><br /> <asp:Button ID="btnConfirmPicks" runat="server" class="btn btn-success" Width="150px" Height="35px" Text="Confirm Picks" CausesValidation="True" TabIndex="35" OnClick="btnConfirmPicks_Click" /> </div> </div> </ItemTemplate> </asp:Repeater> </div><!-- End Of Middle Column --> <div class="col-lg-2 col-md-1 visible-lg visible-md homeBg">Right Col</div> </div><!-- End Main Row --> </div><!-- end of Pool Container --> <!-- Modal --> <div class="modal fade" id="myModal" role="dialog"> <div class="modal-dialog"> <!-- Modal content--> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <h4 class="modal-title"><asp:Label ID="lblWeek" Text='<%#Eval("Week")%>' runat="server" /></h4> </div> <div class="modal-body"> <label class="labelModalInfo">Name:</label> <asp:Label ID="lblFullName" runat="server" /><br /> <label class="labelModalInfo">Text #:</label> <asp:Label ID="lblText" runat="server" /><br /> <label class="labelModalInfo">Referred By:</label> <asp:Label ID="lblReferredBy" runat="server" /><br /> <hr /> <div class="row"> <div class="col-md-4"> <asp:Label ID="lbl_Thursday" runat="server" Text="Thursday. " /><asp:Label ID="lblThursdayGame" runat="server" /><br /> <asp:Label ID="lbl_Turkey1" runat="server" Text="Thanksgiving 1. " /><asp:Label ID="lblTurkeyGame1" runat="server" /><br /> <asp:Label ID="lbl_Turkey2" runat="server" Text="Thanksgiving 2. " /><asp:Label ID="lblTurkeyGame2" runat="server" /><br /> <asp:Label ID="lbl_Turkey3" runat="server" Text="Thanksgiving 3. " /><asp:Label ID="lblTurkeyGame3" runat="server" /><br /> <asp:Label ID="lbl_Sat1" runat="server" Text="Saturday 1. " /><asp:Label ID="lblSatGame1" runat="server" /><br /> <asp:Label ID="lbl_Sat2" runat="server" Text="Saturday 2. " /><asp:Label ID="lblSatGame2" runat="server" /><br /> <asp:Label ID="lbl_Sat3" runat="server" Text="Saturday 3. " /><asp:Label ID="lblSatGame3" runat="server" /><br /> <asp:Label ID="lbl_morning" runat="server" Text="Morning. " /><asp:Label ID="lblMorningGame" runat="server" /><br /> </div> <div class="col-md-4"> 1. <asp:Label ID="lblGame1" runat="server" /><br /> 2. <asp:Label ID="lblGame2" runat="server" /><br /> 3. <asp:Label ID="lblGame3" runat="server" /><br /> 4. <asp:Label ID="lblGame4" runat="server" /><br /> 5. <asp:Label ID="lblGame5" runat="server" /><br /> 6. <asp:Label ID="lblGame6" runat="server" /><br /> 7. <asp:Label ID="lblGame7" runat="server" /><br /> 8. <asp:Label ID="lblGame8" runat="server" /><br /> 9. <asp:Label ID="lblGame9" runat="server" /><br /> <asp:Label ID="lbl_10" runat="server" Text="10. " /><asp:Label ID="lblGame10" runat="server" /><br /> </div> <div class="col-md-4"> <asp:Label ID="lbl_11" runat="server" Text="11. " /><asp:Label ID="lblGame11" runat="server" /><br /> <asp:Label ID="lbl_12" runat="server" Text="12. " /><asp:Label ID="lblGame12" runat="server" /><br /> <asp:Label ID="lbl_13" runat="server" Text="13. " /><asp:Label ID="lblGame13" runat="server" /><br /> <asp:Label ID="lbl_14" runat="server" Text="14. " /><asp:Label ID="lblGame14" runat="server" /><br /> <asp:Label ID="lbl_15" runat="server" Text="15. " /><asp:Label ID="lblGame15" runat="server" /><br /> <asp:Label ID="lbl_16" runat="server" Text="16. " /><asp:Label ID="lblGame16" runat="server" /><br /> <asp:Label ID="lbl_17" runat="server" Text="17. " /><asp:Label ID="lblGame17" runat="server" /><br /> </div> </div> <div class="row"> <hr /> <div class="col-md-12"> <center>Monday Night 1: <asp:Label ID="lblMondayNight1" runat="server" /> <asp:Label ID="lblTotalPointsUser" runat="server" /> pts</center><br /> <center>Monday Night 2: <asp:Label ID="lblMondayNight2" runat="server" /> </div> </div> </div> <div class="modal-footer"> <div class="container-fluid"> <%-- <div class="col-xs-4 col-lg-4"><asp:Button ID="btnSubmit" runat="server" class="btn btn-success" Text="Submit" OnClick="btnSubmit_Click" /></div>--%> <div class="col-xs-4 col-lg-4"><button type="button" class="btn btn-primary" data-dismiss="modal">Edit</button></div> <div class="col-xs-4 col-lg-4"><asp:Button ID="btnCancel" runat="server" class="btn btn-danger" Text="Cancel" OnClick="btnCancel_Cancel" /></div> </div> </div> </div> </div> </div> <script type="text/javascript"> function ValidateRadioButton(sender, args) { var repeater = document.getElementById("<%= myRepeater.ClientID %>"); var items = repeater.getElementsByTagName('input'); for (var i = 0; i < items.length; i++) { if (items[i].type == "radio") { if (items[i].checked) { args.IsValid = true; return; } else { args.IsValid = false; } } } } </script> </asp:Content>