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
Kiran NKiran N 

How do i hide a custom button on detail page of a record until a value in the picklist field is changed to desired value using javascript.

Can someone please help me with the javascript code.I'm a newbie and couldnt figure it out.
How do i hide a custom button on detail page of a record until a value in the picklist field is changed to desired value. Here is my scenario....
I need to create and hide a custom button(eg: Color) .
When the picklist Field( things__c ) value changes to 'Fruit' .....custom buttton 'color' should be visible.
I want to do this with JavaScript only and not visualforce or pagelayouts and record types.I tried the below code but somehow its not working.

$(document).ready(function() {

  //cache the elements we will use
  var $color = $('.color');
  var $things__c = $('#things__c');

   //hide the submit button
  $color.hide()

  //bind event handler to the dropdown field
  $things__c.change(function() {

    //if the user selects what we want, show the submit button

    if ($things__c.find(':selected').val() === "fruit"){
      $color.show();
    }

    //if not, hide it

    else {

      $color.hide();
    }

  });

});
Syed Insha Jawaid 2Syed Insha Jawaid 2
Hi Kiran

It is not possible to hide custom button on pagelayouts as we do not have any control over it.
In order to make its functionality disabled, you can restrict the process until the value for field reaches a desired value.

Cheers!!!!