-1

我有一个master page,下面是一个content page'代码..我无法dropdownlist dpbatchname在 javascript 中找到 's 值..我是javascriptplz 的新手,帮助我想根据该值验证文本框dropdownlist值..

   <asp:Content ID="Content1" ContentPlaceHolderID="Contentplaceholder2" Runat="Server">
   <script  type="text/javascript" language="javascript">
       function ClientValidate(source, arguments) {
           var ddl = document.getElementById("dpbatchname");
           if (ddl.value.length == 2) {
                   arguments.IsValid = true;
               }
               else {
                   arguments.IsValid = false;
               }
           }

   </script>

       <div>
               <table style="width: 100%; background-color:Silver"  border="1">

                <td align="right" width="50%" valign="top">
                           <asp:Label ID="Label3" runat="server" Text="Select Batch:" 
                               Font-Underline="False" ForeColor="#FF3300"  Font-Bold="True" Font-Size="Larger"></asp:Label>
                       </td>
                       <td width="50%" valign="top">
                           <asp:DropDownList ID="dpbatchname" runat="server" AutoPostBack="True" 
                               DataSourceID="SqlDataSource5" DataTextField="batch_name" 
                               DataValueField="batch_name" Width="119px" Height="33px">
                           </asp:DropDownList>
  <asp:TextBox ID="tbnooflecture" runat="server"  Width="113px" Height="33px"></asp:TextBox>
       <asp:CustomValidator id="CustomValidator1" ControlToValidate="tbnooflecture"    ClientValidationFunction="ClientValidate"
     ValidationGroup="upper" Display="Static" ErrorMessage="Not an even number!" ForeColor="green" Font-Name="verdana"    Font-Size="10pt"
      runat="server"/>

                     </td>
       </tr>
       </div>
4

1 回答 1

2

利用

<%=dpbatchname.ClientID %>

获取渲染的 ID:

document.getElementById("<%=dpbatchname.ClientID %>");
于 2013-03-15T18:05:31.427 回答