+ Start a Discussion
Thomas FullerThomas Fuller 

Can you create a custom button with javascript that is able to change the label of the button?

Hey,

I'm in the process of developing a custom button on Salesforce that is able to toggle a checkbox on and off.
At this point, I am using the Salesforce AJAX Toolkit in order to do the main backend functions of the custom button.
I have the backend working, but I was hoping I could have the custom button label toggle between "Start Process" and "End Process".
To do this, I assume I would need the custom button to change it's own label.
I attempted this by placing these lines in my code:
    var toggleButton = new sforce.SObject("Lead");
    var toggleButtonT ="{!Lead.Begin_Touch_Process}"; //my attempt to reference the button
    toggleButtonT.Id = "00bc0000000QoaE"; // my attempt to reference the button id
    toggleButtonT.Label = "test"; // entering new value for the button label
    result = sforce.connection.update([toggleButton]); // updating the button
NOTE:  {!RequireScript} is already mentioned in script.
It's also entirely possible that I cannot change the name of the button with the AJAX Toolkit.

I am very new to Salesforce and learning about this tool, so any ideas or suggestions will be greatly appreciated!


Thanks,
TF
Best Answer chosen by Thomas Fuller
Vishnu_SFDCVishnu_SFDC
Create a button with the logic you want.
Then dispaly the same button in Visualforce page based on value of checkbox with different name.

Example:
<apex:commandButton value="Start Process" action="youfunction"  rendered="{!(yourcheckbox=false)}"/>
<apex:commandButton value="End Process " action="youfunction"  rendered="{!(yourcheckbox=true)}"/>

All Answers

Ramu_SFDCRamu_SFDC
Not sure if we can dynamically change the button name. But I have an idea, why not have two buttons with different names and switch between them dynamically during runtime ?

The below article shows how to dyncamically show button on visualforce page 
http://www.interactiveties.com/b_visualforce_dynamic_buttons.php#.U43j8vlmOo0
Thomas FullerThomas Fuller
I might dig around a little more, but thanks so much!
Vishnu_SFDCVishnu_SFDC
Create a button with the logic you want.
Then dispaly the same button in Visualforce page based on value of checkbox with different name.

Example:
<apex:commandButton value="Start Process" action="youfunction"  rendered="{!(yourcheckbox=false)}"/>
<apex:commandButton value="End Process " action="youfunction"  rendered="{!(yourcheckbox=true)}"/>
This was selected as the best answer
Thomas FullerThomas Fuller
Well, unfortunately, I ran out of time for this project. So, I just split my code between two separate buttons. It still functions correctly, but it is not as fancy as I was hoping to make it. Thanks so much for the replies from the both of you! I will definitely utilize your advice in the future as I dive more into VisualForce pages. Thanks!
_Vish__Vish_

Hi Thomas,

Just wondering if you ended up finding your ideal solution?

And whether it was possible with a custom JavaScript button (without using a custom visualforce page)?

I'm trying to solve the same problem, any insight would be much appreciated.