Saturday, July 31, 2010

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;

                } 
           

1 comment:

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.

Method 'StartWorkflowOnListItem' in type 'Microsoft.SharePoint.WorkflowServices.FabricWorkflowInstanceProvider'

Exception: Method 'StartWorkflowOnListItem' in type 'Microsoft.SharePoint.WorkflowServices.FabricWorkflowInstanceProvider'...