You need to sign in to do that
Don't have an account?
Calculations inside VisualForce Page
Hi, I have a table that needs to pull the result of one custom field multipled by 12 (the current month for the year), for example.
I found this post: http://boards.developerforce.com/t5/Visualforce-Development/simple-calculation-within-page/m-p/532611#M57220 and tried it on my code, but my VF page is not returning any results (it's just blank).
Say the custom field is called "Quantity_This_Year__c" and I need "Quantity_This_Year__c*MONTH(TODAY())" result on the Vf Page.''
I have tried both MONTH(TODAY()) and just the number 12, and still, Vf page is blank next to this field.
Is that other post out of date? Anyone else know a way to perform a calculation where my result will not be blank?
Hi,
Could you please share code snippet of your vf page?
Please find the below working code to acheive uor purpose:
VF page :
<apex:page controller="CalculationOnVFCnt" id="thePage">
<apex:form id="theForm">
<apex:pageblock id="theBlock">
<apex:pageBlockTable value="{!Opportunities}" var="oppty" id="theBlockTable" >
<apex:column headerValue="Name">
<apex:outputField value="{!oppty.Name}"/>
</apex:column>
<apex:column headerValue="Amount">
<apex:outputField value="{!oppty.Amount}"/>
</apex:column>
<apex:column headerValue="Total Amount">
<apex:outputText id="amountM"/>
<script>
var amount = '{!oppty.Amount}';
var d = new Date();
var n = d.getMonth()+1;
var total = amount*n;
var elementId = document.getElementById('{!$Component.amountM}')
elementId.innerHTML= total;
</script>
</apex:column>
</apex:pageblockTable>
</apex:pageblock>
</apex:form>
</apex:page>
And the controller:
public Class CalculationOnVFCnt {
public List<Opportunity> getOpportunities() {
return [select Id,name,amount from opportunity ];
}
}
Please let me know if u have any problem on same.