Solved

Using Javascript to disable asp dropdownlist

Posted on 2006-06-21
4
1,317 Views
Last Modified: 2010-05-18
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?
0
Comment
Question by:Cansler
  • 2
4 Comments
 
LVL 25

Accepted Solution

by:
nauman_ahmed earned 250 total points
ID: 16951081
<script language="javascript">
function CheckDropDownState(lstbox)
{
   if (lstBox.selectedIndex == 2)
   {
       document.forms[0].DropDown1.disabled = 1;
   }
   else
   {
      document.forms[0].DropDown1.disabled = 0;
   }
}
</script>

ASPX.VB
----------
DropDown1.Attributes.Add("onChange","javsacript:CheckDropDownState(this);")

-Nauman.
0
 

Author Comment

by:Cansler
ID: 16951143
Sweet.  Where does the Attributes.Add line go...PageLoad?
0
 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 16951171
Yes. Add it in PageLoad() event.

-Nauman.
0
 
LVL 7

Expert Comment

by:pradeepsudharsan
ID: 16951268
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
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now