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
DipikaDipika 

javascript calling by outfield event

how can we fire an javascript function by clicking on outputfield??

Navatar_DbSupNavatar_DbSup

Hi,

 

Use below code snippets as reference

 

------------  VF page --------------
<apex:page controller="clsforoutputfieldclick">
   <script>
   function chekon()
   {
       alert('hello');
   }
   </script>
   
   
    <apex:form >
  
        <apex:outputpanel id="counter">
            <apex:outputField value="{!concc.name}"/>
            <apex:actionSupport event="onclick" rerender="counter"   status="counterStatus"/>
        </apex:outputpanel>
        <apex:actionStatus id="counterStatus"  onstart="chekon()"/>
    </apex:form>
</apex:page>

-------- Apex Controller ---------------

public class clsforoutputfieldclick 
{
    public contact concc{get;set;}
     Integer count = 0;
                        
public clsforoutputfieldclick()
{
    concc=[select name from contact limit 1];
}
    public PageReference incrementCounter() {
            count++;
            return null;
    }
                    
    public Integer getCount() {
        return count;
    }

}

 Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.