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
rtandon17@gmail.comrtandon17@gmail.com 

Real time calculation of field value based in visual force page

Hi,

I have a requirement where in I have table with 6 fields. The first 5 fields are picklist and sixth one is Number field.

Now ,the user can select any values from each of the picklists and based on the selection of values from the picklist , I will need to perform some numeric calculation and display the numerica value in the 6th field on the fly.

 

Currently my sixth field is a formula field , but the issue is , that formula field calculates and displays only after clicking on the save; Whereas my requirement is that the user can see the change in the value of the 6th field on the fly as and when the user selects or changes the value in any of the first 5 fields.

 

Please help!

 

 

sf@143sf@143
6th field is depending on 5 fields
Sonam_SFDCSonam_SFDC

Hi,

 

Instead of using the 6th field as formula field, you can maybe try the following: 

- you can use actionsupport component on each of the 5 fields.

- create a method in the controller to calculate the value of the 6th field depending on the values of the picklist and return the value in the 6th field.

 

 

rtandon17@gmail.comrtandon17@gmail.com

Can you please share a sample code , as this would be really helpful for me as I am new to SF. Thanks!

rtandon17@gmail.comrtandon17@gmail.com

Thank you! Can you please share a sample code which uses javascript?

SSinghSSingh

 

VF -----------------------

 

<!-- individual fields -->
<apex:inputField id="fld1_id" value="{!fld1}" >
    <apex:actionSupport event="onchange" action="{!calculateFinalValue}" rerender="totalvalue_id"/>
</apex:inputField>
<apex:inputField id="fld2_id" value="{!fld2}" >
    <apex:actionSupport event="onchange" action="{!calculateFinalValue}" rerender="totalvalue_id"/>
</apex:inputField>
<apex:inputField id="fld3_id" value="{!fld3}" >
    <apex:actionSupport event="onchange" action="{!calculateFinalValue}" rerender="totalvalue_id"/>
</apex:inputField>


<!-- final value -->
<apex:outputText id="totalvalue_id" value="{!totalvalue}" />

 

Apex -------------------

Code a method calculateFinalValue to populate the final value in the totalvalue field

rtandon17@gmail.comrtandon17@gmail.com

Hi,

I tried but this does not work.

Can you please provide the complete sample code as I am newbie. Thanks!