Solved

Dropdown disable not working in JQuery or Javascript

Posted on 2013-12-05
6
991 Views
Last Modified: 2013-12-06
I have a JavaScript function that used to work until upgrading to IE 11.  It also doesn't work in either Chrome or FireFox.  

The dropdown is disabled by default, but enabled when a checkbox is changed.

As you can see from the code, I've tried removeAttribute, disabled = false, and finally JQuery.  None seems to be enabling the dropdown.  The alerts show the correct attributes, but in the source it still shows disabled='disabled'.

Any help would be greatly appreciated.

Here's the javascript/JQuery:

        function enableDropDownList(cb) {
            var chkbx = document.getElementById(cb);
            var number = cb.match(justTheDigits);
            var ddlname = "gvCylinderInfo_ctl" + number + "_ddlQtyReassign";
            var ddl = document.getElementById(ddlname);
            //ddl.setAttribute('disabled', 'disabled');
                    alert(ddl.disabled);  //This shows up as 'true'
            if (chkbx.checked) {
                $(ddl).each(function () {
                    this.disabled = false;
                });
                    alert(ddl.disabled);  //This shows up as 'false' - just what I want.
                //ddl.removeAttribute('disabled');
                //ddl.disabled = false;
                document.getElementById('selectCylsPrompt').style.display = 'none';
                document.getElementById('chooseC').style.display = 'block';

            }
            else {
                ddl.disabled = true;
                document.getElementById('selectCylsPrompt').style.display = 'block';
                document.getElementById('chooseC').style.display = 'none';
            }

            enableModify();
        }

Open in new window

When I view source it shows:

<select name="ddlSystem" onchange="javascript:setTimeout(&#39;__doPostBack(\&#39;ddlSystem\&#39;,\&#39;\&#39;)&#39;, 0)" disabled="disabled" id="ddlSystem" class="arial8ptBlack">

Still disabled.

Any ideas?  Thanks.
0
Comment
Question by:IKtech
  • 3
  • 2
6 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39699697
Test page : http://jsfiddle.net/98EjC/

I see : var ddlname = "gvCylinderInfo_ctl" + number + "_ddlQtyReassign";
By you dropdown ID is just : ddlSystem

$("#ddlSystem").removeAttr("disabled");
0
 
LVL 9

Expert Comment

by:Sar1973
ID: 39700642
In JS you must set a true/false boolean value, such as: document.getElementById("myDropdown").disabled=true/false.
Try then to replace disabled="disabled" with disabled="true".
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39700658
@Sar1973 :
Without jQuery the RIGHT way is to use setAttribute() and removeAttribute()

https://developer.mozilla.org/en-US/docs/DOM/element.setAttribute
https://developer.mozilla.org/en-US/docs/DOM/element.removeAttribute
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:Sar1973
ID: 39700666
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39700684
@Sar1973

That will NOT work everytime
Be very careful with W3School resources
0
 
LVL 3

Author Closing Comment

by:IKtech
ID: 39701162
This was only part of it.  There were a few elements disabled.  I just needed to find all of them and do a removeAttribute.

Thanks!
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
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…

685 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