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
Guru Vemuru 1Guru Vemuru 1 

accessing apex class into visualforce javascript

Apex Controller:
public with sharing class DataCompare {

    public DataCompare(ApexPages.StandardController controller) {


 public Policy__c pol {get;set;}
 public string Designation{get;set;}
 public Double PerDiem{get;set;}
 public Double Advance{get;set;} 

 public void DataCompare()
   pol = [select Name , Designation__c, Per_Diem__c, Cash_Advance__c from Policy__c  LIMIT 1];
   System.debug('The record fetched '+pol);

Visual Force: JavaScript

 function showAlert()
            var des='{!Designation}';
            var adv='{!Advance}';
            var sen = "Please confirm by refering policy";
            var amt =  document.getElementById('{!$Component.form1.TRR.TRRR.TRRRR.trAmt}').value ;
            alert("You have entered amount = "+ amt +".\n" +sen+ "" + des+ "" + adv);           

Its not showing Designation and Advance in alert box. Policy is a differnt object and script is on another object.
Asif Ali MAsif Ali M
Move the initialisation code to the below constructor
public DataCompare(ApexPages.StandardController controller) {


Shiva RajendranShiva Rajendran
Hi Guru,
As Asif pointed you ,if you have used the apex class mentioned above as extension to the vf page.Then only the constructor

DataCompare(ApexPages.StandardController controller) {
    } gets called.

Also do share the vf page code to help you serve better.

Thanks and Regards,
Shiva RV