I need to disable one of the custom javascript buttons after the first click. I've found that I can use(and I actually did use this in the past) this 2 lines of code to disable a button:

this.disabled = true;
this.className = 'btnDisabled';

but nothing happens. My button just stays active and clickable. Even if I put an alert('test'); before/after these 2 lines, I do get the alert popup, but the button is still active. Does anyone know what can be the problem(was this feature removed from Winter 16 or one of the previous releases?)? And is there another way to achieve this?


It seems that this way is no longer working since Winter 16(or earlier?). I just checked it in the other org where it did work before, but now it doesn't disable the button anymore.

  • I'm not sure, but isn't this supposed to work only on VisualForce pages? Oct 28, 2015 at 15:20
  • 1
    @RenatoOliveira thanks for your comment. You might be right, find a link that proves your words and I'll gladly accept it as an answer. For now I'm still waiting for an answer with the possible fix
    – Novarg
    Oct 28, 2015 at 15:25
  • This seems to be browser-dependent: In Firefox (Win10), this works. In the Chrome, it doesn't. Even if I use var btnService = document.getElementsByName("button_name"); btnService[0].disabled = true; the button only gets disabled after the following callout is done. So it is useless.
    – georg w.
    Nov 8, 2016 at 12:03

2 Answers 2


Try this:

document.getElementById("yourBtn").addEventListener("click", function(event){
  event.target.disabled = true;
  /*.... other functionality ....*/

You need to create a piece of code that gets the button element and change it's class from btn to btnDisabled. I'm not sure if this is possible in a standard record page, though.

Most searches on this topic are about doing this functionality in a Visualforce page (like this or that). And while this seems to be doable with JavaScript, in the Salesforce Community the suggestion is to do this with a custom Visualforce page.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .