计算asp.net表中的复选框

时间:2014-02-22 13:47:33

标签: javascript asp.net

我对asp和java非常新: 我设计了一个带有表格的页面和该表格中的一些复选框我想用脚本设置一个条件,提醒用户不要检查四个以上的复选框。或者,如果用户选中了四个复选框,则必须禁用此表中可用的其他剩余复选框,如果用户取消选中任何选中的复选框,则所有已禁用的复选框都将被启用以进行新选择。有一些复选框属于同一组(单元格),如果用户单击其中一个,则该组(单元格)中的其他所选复选框必须取消选中,就像在简单地切换一样,只有一个checkbiox必须在该单元格中被选中。我有在java中完成,但不知道如何检查超过四个复选框。 (P.S)在表格的(组I)复选框中,GE被取消和禁用此复选框在四个复选框中是强制性的,应始终检查

<script type="text/javascript">
    function ChkValidate() {
        var counter = 0;


        var panel = document.getElementById ("panel1")
        for (i = 0; i < panel.children.length; i++) {
            if (panel.children[i].type == 'checkbox')
            {
                if (panel.children[i].checked == true) {
                    counter = counter + 1;
                }
            }
            if (counter > 4)

            {
                alert('You have reached to maximum selection');
                return false;

            }
        }
    }
</script>



<script type="text/javascript">

     function aspcheckED0() {
         document.getElementById("PS0").checked = false;
     }
     function aspcheckPS0() {
         document.getElementById("ED0").checked = false;

     }

    function aspcheckEL0() {
        document.getElementById("HS0").checked = false;
        document.getElementById("MA0").checked = false;
     }
     function aspcheckHS0() {
         document.getElementById("EL0").checked = false;
         document.getElementById("MA0").checked = false;
     }
     function aspcheckMA0() {
         document.getElementById("EL0").checked = false;
         document.getElementById("HS0").checked = false;
     }

     function aspcheckUR0() {
         document.getElementById("PJ0").checked = false;
     }
     function aspcheckPJ0() {
         document.getElementById("UR0").checked = false;
     }
     function aspcheckAR0() {
         document.getElementById("PR0").checked = false;
     }
     function aspcheckPR0() {
         document.getElementById("AR0").checked = false;
     }

    </script>



        <table id="artstable" align="center" class="auto-style53" style="border: thin dotted #6666FF; font-family: Verdana;
        border-collapse: collapse; background-color: #E6E6E6;">
            <tr>
                <td align="right" class="auto-style188" colspan="10"><strong>Enter Your Admission Details</strong></td>
            </tr>
            <tr>
                <td align="right" class="auto-style42" colspan="5">
                    <asp:Label ID="lbl" runat="server" Text="Label"></asp:Label>
                    &nbsp;&nbsp;&nbsp;<strong> Select Your Course:</strong></td>
                <td align="right" class="auto-style42" colspan="5">
                    <asp:RadioButtonList ID="rbcourse" runat="server" AutoPostBack="True" Height="54px" RepeatDirection="Horizontal" style="text-align: left; font-weight: 700;" Width="385px">
                        <asp:ListItem>BA</asp:ListItem>
                        <asp:ListItem>BSC</asp:ListItem>
                        <asp:ListItem>BSCN</asp:ListItem>
                        <asp:ListItem>BCOM</asp:ListItem>
                    </asp:RadioButtonList>
                </td>
            </tr>
            <tr>
                <td align="right" class="auto-style140" style="border: thin dotted #0000FF"><strong>B.A</strong></td>
                <td align="left" class="auto-style113" colspan="0">Group&nbsp; 1</td>
                <td class="auto-style162">Group&nbsp; 2</td>
                <td align="left" class="auto-style114">Group 3</td>
                <td align="left" class="auto-style95">Group 4</td>
                <td align="left" class="auto-style150">Group 5</td>
                <td align="left" class="auto-style174">Group 6</td>
                <td align="left" class="auto-style160">Group 7</td>
                <td align="left" class="auto-style136">Group 8</td>
                <td align="left" class="auto-style116">&nbsp;</td>
            </tr>
            <tr>
                <td align="right" class="auto-style140" style="border: thin dotted #0000FF"><span class="auto-style43">Select Any four </span>
                    <br class="auto-style43" />
                    <span class="auto-style43">subjects ,Max one from<br /> each group</span></td>
                <td align="left" class="auto-style117">
                    <asp:CheckBox ID="ge" runat="server" BackColor="#CCFFFF"  Text="GE"   onclick="javascript:return ChkValidate();" SkinID="ch" />
                    <br />
                </td>
                <td align="left" class="auto-style163" rowspan="1">
                    <asp:CheckBox ID="PS" runat="server"  BackColor="#CCFFFF" Text="PS"  onclick="aspcheckPS();" SkinID="ch"/>
                    <br class="auto-style139" />
                    <br class="auto-style139" />
                    <asp:CheckBox ID="ED" runat="server"  BackColor="#CCFFFF"  Text="ED"  onclick="aspcheckED();" SkinID="ch"  />
                </td>
                <td align="left" class="auto-style118">
                    <asp:CheckBox ID="ec" runat="server"  BackColor="#CCFFFF"  Text="EC"  onclick="javascript:return ChkValidate();" SkinID="ch" />
                    <br />
                    <br />
                </td>
                <td align="left" class="auto-style96">
                    <asp:CheckBox ID="kr" runat="server"  BackColor="#CCFFFF"   Text="KR" onclick="javascript:return ChkValidate();" SkinID="ch" />
                    <br />
                </td>
                <td align="left" class="auto-style151" rowspan="1">
                    <asp:CheckBox ID="MA" runat="server" BackColor="#CCFFFF"  Text="MA"  onclick="javascript:return ChkValidate();" SkinID="ch" />
                    <br class="auto-style139" />
                    <br class="auto-style139" />
                    <asp:CheckBox ID="EL" runat="server" BackColor="#CCFFFF"  Text="EL"  onclick="javascript:return ChkValidate();" SkinID="ch"/>
                    <br class="auto-style139" />
                    <br class="auto-style139" />
                    <asp:CheckBox ID="HS" runat="server" BackColor="#CCFFFF"  Text="HS"  onclick="javascript:return ChkValidate();" SkinID="ch"/>
                    <br class="auto-style139" />
                    <br class="auto-style139" />
                    <br class="auto-style139" />
                </td>
                <td align="left" class="auto-style175" rowspan="1">
                    <asp:CheckBox ID="UR" runat="server" BackColor="#CCFFFF"  Text="UR"  onclick="javascript:return ChkValidate();" SkinID="ch"  />
                    <br class="auto-style139" />
                    <br class="auto-style139" />
                    <asp:CheckBox ID="PJ" runat="server"  BackColor="#CCFFFF"  Text="PJ" onclick="javascript:return ChkValidate();" SkinID="ch"  />
                    <br class="auto-style139" />
                </td>
                <td align="left" class="auto-style161" rowspan="1">
                    <asp:CheckBox ID="AR" runat="server" BackColor="#CCFFFF"  Text="AR"  onclick="javascript:return ChkValidate();" SkinID="ch"  />
                    <br class="auto-style139" />
                    <br class="auto-style139" />
                    <asp:CheckBox ID="PR" runat="server" BackColor="#CCFFFF"  Text="PR" onclick="javascript:return ChkValidate();" SkinID="ch"  />
                </td>
                <td align="left" class="auto-style137">
                    <asp:CheckBox ID="fe" runat="server" BackColor="#CCFFFF"  Text="FE"  onclick="javascript:return ChkValidate();" SkinID="ch"  />
                </td>
            </tr>
        </table>

0 个答案:

没有答案