+ Start a Discussion
Chandra babu 2Chandra babu 2 

how two sum two custom fields and Display the values in another column.

User-added image

i will give Amount and Discount Values,But i want  Two values Calculated display the netprice in UI page.plese tel me.
Alexander TsitsuraAlexander Tsitsura

You need to create apex controller, for summarize this fields.

For example vf page
<apex:page controller="AmountController">
  <apex:form id="frm">
      <apex:pageBlock >
          <apex:pageBlockSection columns="1">
              <apex:inputText label="Amount" value="{!amount}" >
                  <apex:actionSupport event="onchange" reRender="frm"/>
              <apex:inputText label="Discount" value="{!discount}" >
                  <apex:actionSupport event="onchange" reRender="frm"/>
              <apex:outputText value="{0, number, currency}" label="net Price" >
                  <apex:param value="{!newPrice}" />
and apex controller
public with sharing class AmountController {
    public Decimal amount {
        set {
            // when changed amount value, recalc newPrice value
            if (value != amount) {
                amount = value;
    public Decimal discount {
        set {
            // when changed discount value, recalc newPrice value
            if (value != discount) {
                discount = value;
    public Decimal newPrice {
        private set;
    public AmountController() {
        this.amount = 0;
        this.discount = 0;
    private void recalcNewPrice() {
        newPrice = (null == amount ? 0 : amount) 
                 + (null == discount ? 0 : discount);

Ajay K DubediAjay K Dubedi
Hi Chandra,

The below code can be used as per ur requirement. But in the following code i am using an controller for this and not using any fields. If you want to use any custom fields on any object than you can query the field value in place of <apex:inputtext> and modify the code as per your requirment.
public with sharing class sumcls {
    public integer sum {get;set;}
    public integer discount {get;set;}
    public integer out {get;set;}
    public sumcls(){
    public pagereference result(){
        out = sum-discount;
        return null;
<apex:page controller="sumcls">
    <apex:actionFunction name="test" action="{!result}" reRender="go">                     
            <apex:inputText value="{!sum}" label="Sum"/> <br> </br>
            <apex:inputText value="{!discount}" label="Discount" onkeyup="test();"/>
      <!--      <apex:pageBlockButtons>
                <apex:commandButton action="{!result}" value="result"/>   
            </apex:pageBlockButtons>   -->
            <apex:outputText value="{!out}" label="this is result" id="go"/>
You can use the javascript to calculate the value and assign to output field with out any server call