Activity › Forums › Salesforce® Discussions › Calculation on Visualforce Page without using Controller
Tagged: Apex Repeat, Integer, Salesforce Apex Variable, Salesforce Controller, Salesforce Visualforce Page
-
Calculation on Visualforce Page without using Controller
Posted by Gaurav on April 14, 2016 at 4:43 AMHi,
I am showing an integer field on my visualforce page for each record. I need to calculate the total of that field and display it on page without using controller.
How can i achieve this?
Parul replied 7 years, 7 months ago 4 Members · 3 Replies -
3 Replies
-
$(document).ready(function(){
var count = 0;
count+=$(‘:input’).length;
count+=$(“select”).length;
var datalistCount =$(“datalist”).length;
count+= datalistCount;
count+=$(“textarea”).length;
$(“.TotalCountOfField”).val(count – 1 – datalistCount);
}); - [adinserter block='9']
-
Hi Gaurav,
Another method to calculate total of your field is by using <apex:variable>.
For example i am displaying my field in <apex:repeat>. Then i will use apex variable like this:-
<apex:variable var=”i” value=”{!0.00}”/>
<Table>
<apex:repeat value=”{!Value}” var=”item”>
<tr>
<td> {!item.FieldName}
<apex:variable var=”i” value=”{!i+item.FieldName}”/>
</td>
</tr><tr>
<td>
Total : {!i}
</td>
</apex:repeat>
</Table>This way the total of field value will be displayed.
-
Create two variable and then add with ‘+’ in third variable in apex page without any controller.
Try this code snippet:
<apex:page standardController=”Property__c”>
<apex:outputText value=”Purchase: “/><apex:outputText value=”{0, number, $###,###}”><apex:param value=”{!Property__c.PurchPrice__c}” /></apex:outputText><br/>
<apex:outputText value=”Rehab: “/><apex:outputText value=”{0, number, $###,###}”><apex:param value=”{!Property__c.TotalRehab__c}” /></apex:outputText><br/>
<apex:outputText value=”Total: “/><apex:outputText value=”{0, number, $###,###}”><apex:param value=”{!Property__c.PurchPrice__c + Property__c.TotalRehab__c}” /></apex:outputText><br/>
</apex:page>Thanks.
Log In to reply.