+ Start a Discussion
kirubakaran viswanathankirubakaran viswanathan 

How to use <a> tag inside Apex:outputText in Visualforce?

I need to display the email id with link based on program name in a para. How can I acheive in VF?
<p class = "doc-preview__copy txindent">
               If you have any questions regarding your next steps, please contact the {!TargetX_SRMb__Application__c.Program_Name__c} 
               admissions team  
                <apex:outputText value="{!IF(app.Program_Name__c == "abc", <a href="mailto:abc@abc.com">abc@abc.com</a>.,a href="mailto:123@abc.com">123@abc.com</a>
                                        ')}" />
   </p>
I am getting syntax error or EL Expression unbalanced error.


 
Ajay K DubediAjay K Dubedi
Hi Kirubakaran,     
     
You can simply use the anchor tag to achieve this functionality

    <apex:outputText label="fieldLabel" value="{!Object.fieldValue}"/>
    <a href="javascript:window.open('url')">
     Change
    </a>
    
And with the use of outputLink:

<apex:outputLink onclick="javascript:window.open('url')">
   Change
 </apex:outputLink>
 
 refer this url:
 https://salesforce.stackexchange.com/questions/46318/outputtext-with-link
 
 http://www.infallibletechie.com/2013/02/apexoutputlink-in-salesforce.html
                       
Please mark it as best Answer if you find it helpful.

Thank You
Ajay Dubedi
kirubakaran viswanathankirubakaran viswanathan
HI Ajay,

How can use with IF logic? 
Akshay_DhimanAkshay_Dhiman
Hi Kirubakaran

 try this code
 
 
<apex:outputLink value="{!IF(app.Program_Name__c == "abc",mailto:abc@abc.com,mailto:123@abc.com)}">
  {!TargetX_SRMb__Application__c.Program_Name__c}
 </apex:outputLink>

 
 If you found this answer helpful then please mark it as best answer so it can help others.

 
 Thanks 
 Akhsay
kirubakaran viswanathankirubakaran viswanathan
Hi Akshay,

I tried this, getting syntax error
<apex:outputLink value="{!IF(app.Program_Name__c == "abc",mailto:abc@abc.com,mailto:123@abc.com)}" />


 
kirubakaran viswanathankirubakaran viswanathan
IF PROGRAM A - Display this text:
If you have any questions regarding your next steps, please contact the PROGRAM A admissions team in the Office of Executive Education at abc@abc.com.

or

IF PROGRAM B - Display this text:
If you have any questions regarding your next steps, please contact the PROGRAM B admissions team in the Office of Executive Education at 123@abc.com.


Here program name display from field in SF record, I need put static Email here.
Ajay K DubediAjay K Dubedi
Hi Kirubakaran,    

Please use this in your code for if condition.
I hope you understand this. 
 
 <apex:page>

<apex:variable value="showSecond" var="myVar" />

<apex:outputlink rendered="{!myVar=='showFirst'}" >I am FIRST link</apex:outputlink>

<br/>

<apex:outputlink rendered="{!myVar=='showSecond'}" >I am SECOND link</apex:outputlink>

<apex:page>
                       
Please mark it as best Answer if you find it helpful.

Thank You
Ajay Dubedi