Solved

Using Javascript to disable asp dropdownlist

Posted on 2006-06-21
4
1,310 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

746 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

10 Experts available now in Live!

Get 1:1 Help Now