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
WilmerWilmer 

How to show a custom label value on a onclick property set as Javascript?

Hi,

 

I would like to know how can I show a custom label value into a message displayed by an onclick event in a Command Link button.

 

In example

<apex:commandLink value="{!$Label.MyLabel1}" onclick="return confirm('Are you sure?')" action="{!removeItem}">
   <apex:param name="removeItemId" value="{!item.objId}" assignTo="{!selectedItemId}" />
</apex:commandLink>

 

I would like to replace the hard coded 'Are you sure?' message by a custom Label value, but everytime I try, the related button doesn't  work properly. Any kind of suggestion?

 

Regards,

 

Wilmer

 

 

Best Answer chosen by Admin (Salesforce Developers) 
WilmerWilmer

The answer is easy...

 

<apex:commandLink value="{!$Label.MyLabel1}" onclick="return confirm('{!$Label.QuestionLabel}')" action="{!removeItem}">
   <apex:param name="removeItemId" value="{!item.objId}" assignTo="{!selectedItemId}" />
</apex:commandLink>

All Answers

WilmerWilmer

The answer is easy...

 

<apex:commandLink value="{!$Label.MyLabel1}" onclick="return confirm('{!$Label.QuestionLabel}')" action="{!removeItem}">
   <apex:param name="removeItemId" value="{!item.objId}" assignTo="{!selectedItemId}" />
</apex:commandLink>
This was selected as the best answer
Michael Bos 3Michael Bos 3
I know this is a very old threat, but it's exactly what I want to use.
I would like to use this custom label within onclick="return confirm" but for me it's not working.

This works > onclick="return confirm ('Warning')"
This does not > onclick="return confirm('{!$Label.Custom_Label}')"

This is within a visualforce page
Current code:
 
<div class="slds-form-element__control">
                <apex:commandButton onclick="return confirm('Warning Message');" action="{!split}" value="Split"/>
            </div>

Current visualforce page works fine.