function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
salesforce developer 348salesforce developer 348 

how to enable and disable picklist values based on onclick javascript button.


I have one custom object (gpt__DupesPreventor_Setting__c) & it has one picklist field which contains all sObjects in our org (gpt__Enable_Object__c).

I made one custom Visualforce Page & i want to show this picklist values based on javascript onclick button.


When i select a one sObject from this PickList then it enable (& Emidiatly show "Disable " button in front of these selected sObject).


When i click on this "Disable" button, then these perticular records gets "Disable".


Hopes someone from this community, coz i already wasted my two days to reasrech on this specific task.


Anyone Help greatly appreciate.




Arun ParmarArun Parmar

Simply you can use  $(".option").attr("disabled", "disabled");

.option is the class name of options in selectList which you need to disable.

Hope it will help you.
Ajay K DubediAjay K Dubedi
Hi ,

Please try the below code and let me know if this works for you. If still need modifications do let me know.

 <apex:form id="frm">
        <apex:selectList multiselect="false" size="1" id="pkList" >
            <apex:selectOptions value="{!accNames}">
     <apex:commandButton value="dis" onclick="fun();return false;" />   
        function fun (){
            document.getElementById('{!$Component.frm.pkList}').disabled = true; 

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Ajay Dubedi