7
Answers

Drop down disabled

Hello all,
here i have two dropdowns. dropdown1 and  dropdown2 
In drop down1  Have three items like item1, item2, item3
if i select item3 in dropdown1.  drop down2 will disabled. if i select item1 or item2 drop down 2 will enable....
Need code  in Jquery 
Please help me... 
Thanks in Advance.......
Answers (7)
1
Abrar Ahmad Ansari

Abrar Ahmad Ansari

NA 679 21.2k 9y
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Report.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
 
    <script src="Scripts/jquery-2.1.3.min.js"></script>
    <script>
        $(document).ready(function () {

            $('#ddlMain').change(function () {

                if( $('#ddlMain').val()=="Item2")
                {
                    $('#ddlChild').hide();
                }
                else
                {
                    $('#ddlChild').show();
                }
            });
        });

    </script>
</head>
<body>
    <form id="form1" runat="server">
       
             <asp:DropDownList ID="ddlMain" runat="server" Width="200px">
                  <asp:ListItem>select</asp:ListItem>
                 <asp:ListItem>Item1</asp:ListItem>
                 <asp:ListItem>Item2</asp:ListItem>
                 <asp:ListItem>Item3</asp:ListItem>

             </asp:DropDownList> &nbsp;&nbsp;&nbsp;&nbsp;
         <asp:DropDownList ID="ddlChild" runat="server" Width="200px">
                 <asp:ListItem>select</asp:ListItem>
                 <asp:ListItem>Item1</asp:ListItem>
                 <asp:ListItem>Item2</asp:ListItem>
                 <asp:ListItem>Item3</asp:ListItem>
             </asp:DropDownList>
    </form>
</body>
</html>

Accepted
0
Hareesh Bollepalli

Hareesh Bollepalli

NA 93 29.4k 9y
Thanks Abrar Ahmad Ansari it's working
0
Sanjeeb Lenka

Sanjeeb Lenka

NA 22.1k 1.3m 9y
Is that help you or not.
0
Hareesh Bollepalli

Hareesh Bollepalli

NA 93 29.4k 9y
:(
0
Sanjeeb Lenka

Sanjeeb Lenka

NA 22.1k 1.3m 9y

Try this



<head>
<script>
function disable() {
if(document.getElementById("mySelect").selectedIndex>0)
    document.getElementById("mySelect2").disabled=true;
else
 document.getElementById("mySelect2").disabled=false;
}
function disable2() {
if(document.getElementById("mySelect2").selectedIndex>0)
    document.getElementById("mySelect").disabled=true;
else
 document.getElementById("mySelect").disabled=false;
}

</script>
</head>
<body>

<form>
<select id="mySelect" onChange="disable();">
  <option>Select</option>
  <option>Item1</option>
  <option>Item2</option>
  <option>Item3</option>
</select>

<select id="mySelect2" onChange="disable2();">
<option>Select</option>
  <option>A</option>
  <option>B</option>
  <option>c</option>
</select>
<br><br>

</form>

</body>
</html>

0
Hareesh Bollepalli

Hareesh Bollepalli

NA 93 29.4k 9y
Here only two drop downs if select selected item in first drop down automatically second drop down will disabled no need buttons.
-1
Dipankar Biswas

Dipankar Biswas

NA 3k 125.5k 9y
 Hi
 
 simple example here..
  <head>
<script>
function disable() {
    document.getElementById("mySelect").disabled=true;
}
function enable() {
    document.getElementById("mySelect").disabled=false;
}
</script>
</head>
<body>

<form>
<select id="mySelect">
  <option>Item1</option>
  <option>Item2</option>
  <option>Item3</option>
</select>

<select id="mySelect2">
  <option>A</option>
  <option>B</option>
  <option>c</option>
</select>
<br><br>
<input type="button" onclick="disable()" value="Disable list">
<input type="button" onclick="enable()" value="Enable list">
</form>

</body>
</html>

  Option select event..1. http://stackoverflow.com/questions/898463/fire-event-each-time-
a-dropdownlist-item-is-selected-with-jquery

                              2.http://stackoverflow.com/questions/20976497/jquery-change-event-on-dropdown

  Thanks...