Click here to Skip to main content
15,879,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

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
 
Share this answer
 
Hi,

i did some code for your requirement

check this once

HTML
<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
 
Share this answer
 
Comments
Ganesh_mca 3-Nov-11 9:57am    
Thank u So Much its working perfevtly
Muralikrishna8811 3-Nov-11 9:58am    
most welcome

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900