1

I have two DropDownList

<asp:DropDownList ID="ddl1" runat="server" Width="173px" 
                                CssClass="ddl" >
                            </asp:DropDownList>

<asp:DropDownList ID="ddl2" runat="server" Width="173px" 
                                CssClass="ddl" Enabled="False">
                            </asp:DropDownList>

I want when the first one will be ddl1.selectedindex = 3 to enable the second one ddl2

2
  • Use OnSelectedIndexChanged for ddl1 Commented Mar 19, 2012 at 10:47
  • OnSelectedIndexChanged is only needed if you want to populate the values of ddl2 on the fly, it causes a postback to do that. Commented Mar 19, 2012 at 11:04

3 Answers 3

2

You can use the .change event to check the selected value.

demo: http://jsfiddle.net/m8dX3/

javascript:

$('#ddl1').change(function(){
    var ddl1=$(this);
    var ddl2=$('#ddl2');
    if (ddl1.val()==3) { ddl2.removeAttr('disabled'); }
    else { ddl2.attr('disabled','disabled').val(0); }
});

and make sure you use the correct ClientID of the dropdownlists ($('#<%=ddl1.ClientID%>')) or use a classname.

Sign up to request clarification or add additional context in comments.

Comments

2

Try this:

if($('[id$="ddl1"]').val() == 3) {
   $('#ddl2').attr("disabled") = "disabled";
}

2 Comments

Wouldn't you want $('#ddl2').attr("disabled") = "disabled";? The values for disabled are either "disabled" or "".
No problem, I have made that same mistake =)
0

Just to provide the non-jquery inline approach:

<asp:DropDownList ID="ddl1" runat="server" Width="173px" 
     CssClass="ddl" onchange="if (this.selectedIndex=3) {document.getElementById('ddl2').disabled=false;}">
                            </asp:DropDownList>

<asp:DropDownList ID="ddl2" runat="server" Width="173px" 
                                CssClass="ddl" Enabled="False">
                            </asp:DropDownList>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.