Solved

Java Script to disable all dropdown boxes on page (exclude other controls)

Posted on 2008-10-04
4
1,066 Views
Last Modified: 2012-05-05
I am looking for a simple way to reference all the dropdown controls on a page, and disable them when a particular text box's text is changed. My page has other elements, such as text boxes and radio selectors, but I do not want them to be affected.

In other words, an OnClick event for a particular text box, calls a routine which disables all the dropdown boxes.


This is what I was thinking...
 
function disabledropdowns()
{
document.getElementByType("dropdown").disabled=true
}

Open in new window

0
Comment
Question by:andrejonker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 11

Accepted Solution

by:
petiex earned 500 total points
ID: 22643137
This should do it:

function disabledropdowns()
            {
                var selects = document.getElementsByTagName("select");
                for (var i=0; i<selects.length; i++){
                    selects[i].disabled = true;    
                }
            }
0
 

Author Comment

by:andrejonker
ID: 22643949
Maybe it is lack of sleep, but I don't see why nothing happens... I called the above as follows:

<asp:TextBox runat="server" id="CustomerName" width="500px" onchange="javascript: disabledropdowns()">ReplaceWithCustomerName</asp:TextBox>

And in my page head, I have:


<script language="javascript" type="text/javascript">
    function disabledropdowns()
    {
        var selects = document.getElementsByTagName("select");
        for (var i = 0; i < selects.length; i++)
        {
            selects[i].disabled = true;
        }
    }
</script>

0
 
LVL 11

Expert Comment

by:petiex
ID: 22645892
What does the HTML rendered from your ASP code look like when you view-source on the rendered page?
 I think that with ASP, you may need to add the onchange attribute programmatically as described here: http://www.aspdev.org/articles/asp.net-javascript-add.attributes/
0
 

Author Comment

by:andrejonker
ID: 22645941
Changed it to:
asp:TextBox runat="server" id="CustomerName" width="500px" onchange="disabledropdowns()">ReplaceWithCustomerName</asp:TextBox>

and now the HTML result looks like:
<input name="CustomerName" type="text" value="ReplaceWithCustomerName" id="CustomerName" class="field_input" onchange="disabledropdowns()" style="width:500px;" />



0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# Windows Form Navigation - Total Beginner 9 46
C# LINQ 5 25
Broken .resx file generating errors 18 20
asp.net repeater 2 11
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

733 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