Link to home
Start Free TrialLog in
Avatar of Cansler
Cansler

asked on

Using Javascript to disable asp dropdownlist

Check this problem out:  

I have two asp:dropdownlist controls on a page.  If you select option 3 in the first drop down, then the second drop down should become disabled.  If you select anything other than option 3 in the first drop down, then the second dropdown should be (re)enabled.

It would be nice to do this client-side.  Can javascript do this?
ASKER CERTIFIED SOLUTION
Avatar of nauman_ahmed
nauman_ahmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Cansler
Cansler

ASKER

Sweet.  Where does the Attributes.Add line go...PageLoad?
Yes. Add it in PageLoad() event.

-Nauman.
hi,
try
this
 'Server Side
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
             DropDownList1.Attributes("onchange") = "ChangeDrpDown2()"
    End Sub

//Client side java script
function ChangeDrpDown2()
            {
            
                if(document.Form1["DropDownList1"].options.value==3)
                {
                  document.Form1["DropDownList2"].disabled=true;
                }
                else
                {
                 document.Form1["DropDownList2"].disabled=false;
                }
            }

regards
pradeep