带有验证的下拉列表Javascript [英] Dropdownlist Javascript with validation
本文介绍了带有验证的下拉列表Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨gdmrng ...
我有三个具有相同值的下拉列表,例如A,B,C,我想了解使用Javascript的下拉列表中的验证,如果我从dropdownlist1中选择任何值,则在第二个下拉列表中不选择相同的值,就像在第二,第三下拉列表中
感谢adnvace
Hi gdmrng...
I have three dropdownlists with the same values like A,B,C,i want to know about the Validations in dropdownlists using Javascript, if i select any value from the dropdownlist1 then in the second dropdownlist not select the same value in this,same as in the second,third dropdownlist
thanks in adnvace
推荐答案
Ganesh
这是我的建议,您可以使用级联的dropdownlist控件(即ajax控件),然后您可以接收以下o/p
Hi Ganesh
it''s my suggestion you can use the cascading dropdownlist control(that is a ajax control) for that then u can aceive the following o/p
我为您的要求做了一些代码
一次检查一次
Hi,
i did some code for your requirement
check this once
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script language ="javascript" >
function check1(tid) {
var len = document.getElementById("DropDownList2").options.length;
var j = 0;
for (var i = 0; i < len; i++) {
if (document.getElementById("DropDownList2").options[i].value == document.getElementById(tid).value) {
j = i;
}
}
document.getElementById("DropDownList2").options[j].disabled = "disabled";
}
function check2(tid) {
var len = document.getElementById("DropDownList3").options.length;
var j = 0;
for (var i = 0; i < len; i++) {
if (document.getElementById("DropDownList3").options[i].value == document.getElementById(tid).value) {
j = i;
}
}
document.getElementById("DropDownList3").options[j].disabled = "disabled";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:dropdownlist id="DropDownList1" runat="server" onchange="check1(this.id)" xmlns:asp="#unknown">
<asp:listitem text="first" value="first"></asp:listitem>
<asp:listitem text="second" value="second"></asp:listitem>
<asp:listitem text="third" value="third"></asp:listitem>
<asp:listitem text="fourth" value="fourth"></asp:listitem>
</asp:dropdownlist>
<asp:dropdownlist id="DropDownList2" runat="server" onchange="check2(this.id)" xmlns:asp="#unknown">
<asp:listitem text="first" value="first"></asp:listitem>
<asp:listitem text="second" value="second"></asp:listitem>
<asp:listitem text="third" value="third"></asp:listitem>
<asp:listitem text="fourth" value="fourth"></asp:listitem>
</asp:dropdownlist>
<asp:dropdownlist id="DropDownList3" runat="server" xmlns:asp="#unknown">
<asp:listitem text="first" value="first"></asp:listitem>
<asp:listitem text="second" value="second"></asp:listitem>
<asp:listitem text="third" value="third"></asp:listitem>
<asp:listitem text="fourth" value="fourth"></asp:listitem>
</asp:dropdownlist>
</div>
</form>
</body>
</html>
我希望你能理解我的所作所为
最好的
I hope you understood what I did
All the Best
这篇关于带有验证的下拉列表Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文