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
mukul shah 14mukul shah 14 

Button active or inactive based on picklist value

Hi Everyone,

I have a button and picklist field .. I have to keep the button active when the status is  A and B  and keep it inactive when the status is C. How can I do this? Do I need to write a trigger? Pls help

Rohit K SethiRohit K Sethi
Hi Mukul,

        <script   src=""></script>
            function btnDisable(label){
                    var pick1Text = $('[id$=pick1]').find('option:selected').text();
                    if(pick1Text=="A" || pick1Text=="B"){
        Select Value ::
        <apex:inputField id="pick1" value="{!contact.status__c}" onchange="btnDisable(this);"/><br/>
        <apex:commandButton value="Click Me" id="myButton"/>
You don't need to write any trigger. 

mukul shah 14mukul shah 14
Hi Rohit,

I already have some script on that button to set a particular value on click..


var p = new sforce.SObject('Account'); = "{!Account.Id}";
p.Account_Sync_Status__c = "Submitted";
result = sforce.connection.update([p]);

Now i need to add script to keep it active when the picklist value is New/Modified and Inactive/greyed out when value is Submitted/Synced.
How would i merge the code with the existing one?

Rohit K SethiRohit K Sethi
Hi Mukul,

You are calling asynchronous call that is 
                result = sforce.connection.update([p]);
and after that you are reloading the page this will immediately reload the page . So you need to set callback in sforce request and that callback will execute the reload code.One more thing you should Set that is session id.

I am posting code that can help you to better understand.
sforce.connection.sessionId = '{!$Api.Session_ID}';
                var callback = {                
                 onSuccess:function(result){        alert("success" + result);      location.reload(true); }, 
                 onFailure:function(error){         alert("error" + error);    location.reload(true); } 
                var p = new sforce.SObject('Account');
       = "{!}";
                p.Name = "rohit";
                result = sforce.connection.update([p],callback);

If this post solves your problem kindly mark it as solution.