How to disable CheckBoxList using Javascript

I have faced this problem very recently,how to disable CheckBoxList using Javascript. It is not possible to disable like other object(textbox,combobox..) . After goggling I have found the solution now its sharing with you.....

Javascript code:
               // Get the checkboxlist object.
                var objCtrl = document.getElementById('<%=chkNeighborhoodFeatures.ClientID %>');                // Does the checkboxlist not exist?
                if(objCtrl == null)
                {        return;
                }

                var i = 0;
                var chkNeighborhoodFeaturesArray = objCtrl.getElementsByTagName('input');
                // iterate through listitems that need to be enabled or disabled
                for(i = 0; i
                {
                    objItem = document.getElementById('<%=chkNeighborhoodFeatures.ClientID %>' + '_' + i);
                    if(objItem == null)
                    {
                     continue;
                    }
                    // Disable/Enable the checkbox.
                    objItem.disabled = true;
                    // Should the checkbox be disabled?
                    objItem.checked = false;

                } 
           

Comments

Anonymous said…
Part of you for loop was truncated:

for(i = 0; i

Should be:

for(i = 0; i<chkneighborhoodfeaturesarray.length; i++)

I got the missing part by doing a view source.

Your code works but is there a way to also dim the text? It's hard to tell that the checkboxes are disabled.

Popular posts from this blog

The model backing the 'MyDBContext' context has changed since the database was created. Either manually delete/update the database, or call Database.SetInitializer with an IDatabaseInitializer instance. For example, the DropCreateDatabaseIfModelChanges strategy will automatically delete and recreate the database, and optionally seed it with new data.

How can I get a value of a property from an anonymous type (C#)

Check/Uncheck all items in a CheckBoxList using Javascript