function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Santosh SSantosh S 

multiplying values of Two Number Fields & display in 3rd Field

Request help in multiplying values in Two  Fields (UnitPrice__c  & QuantitySold__c}

& display the value in edit mode in 3rd Field (TotalSale__c)

 

All the 03 Fields are  Number type

 

 -----------------------------------VF Page------------------------------------------------------------------------------
               
  <apex:inputField id="IDUnitPrice" value="{!opportunity.UnitPrice__c}" ></apex:inputField>
  <apex:inputField id="IDQtySold" value="{!opportunity.QuantitySold__c}"  onkeyup="javascript&colon;CalculateAmount();">  

  </apex:inputField>
  <apex:inputField id="IDTotalSale" label="Total Sale" value="{!opportunity.TotalSale__c}"></apex:inputField>
 ------------------------------------Script -----------------------------------------------------------------------------------

function CalculateAmount()
      {  
        
         var Price =  VALUE(UnitPrice__c.);
         var Qty = VALUE(QuantitySold__c);
         
         var Amount =  Price * Qty;      
      
         VALUE(TotalSale__c) = Amount;
      }

Best Answer chosen by Admin (Salesforce Developers) 
kiranmutturukiranmutturu

this is the sample code

 

<apex:page standardController="lead">
<apex:form>

<apex:inputField id="id1" value="{!lead.NumberofLocations__c}"/>

<apex:inputField id="id2" value="{!lead.Total_Activites__c}" onblur="fix(document.getElementById('{!$component.id1}').value,this.value)"/>

<apex:inputField id="id3" value="{!lead.NumberOfEmployees}"/>

<script>

function fix(var1,var2){
alert(var1+"****"+var2);
document.getElementById('{!$component.id3}').value = var1 * var2;

}


</script>

</apex:form>
</apex:page>

All Answers

kiranmutturukiranmutturu

this is the sample code

 

<apex:page standardController="lead">
<apex:form>

<apex:inputField id="id1" value="{!lead.NumberofLocations__c}"/>

<apex:inputField id="id2" value="{!lead.Total_Activites__c}" onblur="fix(document.getElementById('{!$component.id1}').value,this.value)"/>

<apex:inputField id="id3" value="{!lead.NumberOfEmployees}"/>

<script>

function fix(var1,var2){
alert(var1+"****"+var2);
document.getElementById('{!$component.id3}').value = var1 * var2;

}


</script>

</apex:form>
</apex:page>

This was selected as the best answer
Chandra babu 2Chandra babu 2
hi Kiran
User-added image

Hi Kiran i will give amount ant Discount values but i want to calculated amount Display in Net price tel me pls.
Samiullah saudagarSamiullah saudagar
Thanks @kiranmutturu