You need to sign in to do that
Don't have an account?
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);
Designation='pol.Designation__c';
PerDiem=pol.Per_Diem__c;
Advance=pol.Cash_Advance__c;
}
}
Visual Force: JavaScript
<script>
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);
}
</script>
Its not showing Designation and Advance in alert box. Policy is a differnt object and script is on another object.
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);
Designation='pol.Designation__c';
PerDiem=pol.Per_Diem__c;
Advance=pol.Cash_Advance__c;
}
}
Visual Force: JavaScript
<script>
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);
}
</script>
Its not showing Designation and Advance in alert box. Policy is a differnt object and script is on another object.
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