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
Dev87Dev87 

VisualForse Page: Calculated Field

Hello Every one, 
I want to automatically calculate a field in my visualforce page from the multiplication of two other fields (in the same page).
Thank you in advance
SandhyaSandhya (Salesforce Developers) 
Hi,

Refer below 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>

Please mark it as solved if my reply was helpful. It will make it available for other as the proper solution.
 
Best Regards
Sandhya
 
Dev87Dev87
Thanks for Replay, 
had to add   form's id  to $Component
exemple 
<apex:inputField id="id2" value="{!lead.Total_Activites__c}"onblur="fix(document.getElementById('{!$component.id1}').value,this.value)"/>
changed to 

document.getElementById('{!$Component.form1.thePageBlock.thePageSection.id1}')
(form1  is form's id, thePageBloc is pagebloch's id and PageSection is pageserction's id)