+ Start a Discussion

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?




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 headerValue="Amount">
                    <apex:outputField value="{!oppty.Amount}"/>
                <apex:column headerValue="Total Amount">
                    <apex:outputText id="amountM"/>  
                        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;



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.
Anna Lu 6Anna Lu 6
I have similar problem here, and I tried everyone's suggestion -- not working...