下拉列表中的验证问题 [英] validation problem in dropdown list
本文介绍了下拉列表中的验证问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
if (document.getElementById("<%=DropDownList6.ClientID%>").value == "0")
{
alert("Please fill the Event Starting Time");
document.getElementById("<%=DropDownList6.ClientID%>").focus();
return false;
}
这是代码...但是无法正常工作,可以告诉我这段代码有什么问题...
this is the code...but its not working can any 1 tell me whats the problem with this code...
推荐答案
尝试一下:
Try this:
function fnValidate()
{
if(document.getElementById('<%=ddlTest.ClientID%>').selectedIndex == 0)
{
alert("Please select from drop down");
return false;
}
return true;
}
--Amit
--Amit
您也可以尝试这个
Hi ,
You could also try this one
<div>
<asp:Button ID="Button2" runat="server" Text="Button" ValidationGroup="ss" />
<asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="True"
ValidationGroup="ss">
<asp:ListItem Text="---select---" Value="0" ></asp:ListItem>
<asp:ListItem Text="---test---" Value="1" ></asp:ListItem>
</asp:DropDownList>
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToValidate="DropDownList1" Display="Dynamic"
ErrorMessage="CompareValidator" ForeColor="#FF3300" Operator="GreaterThan"
SetFocusOnError="True" ValueToCompare="0" ValidationGroup="ss"></asp:CompareValidator>
</div>
最好的问候
M.Mitwalli
Best Regards
M.Mitwalli
我可以建议一个替代方案吗?
为什么不尝试RequiredFieldValidator?为第一个元素提供一个空值,并将您的验证器定向到Dropdownlist6.
Can I suggest an Alternative?
Why not try RequiredFieldValidator? Provide an empty value for the first element and direct your validator to the Dropdownlist6.
这篇关于下拉列表中的验证问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文