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
Amit Jadhav 13Amit Jadhav 13 

I am Creating A VF Page For two number field calculation and save calculation in 3rd number field dynamically can it is possible

Best Answer chosen by Amit Jadhav 13
NagendraNagendra (Salesforce Developers) 
Hi Amit,

You can use JavaScript and jQuery to calculate the sum of the two fields and use the help of onchange method and populate into the third field.

Here is the code:
<apex:page id="page" standardController="Employee__c">
    <apex:form id="form">
        <apex:pageBlock id="pgblk" mode="edit" title="Employee Edit">
            <apex:pageBlockSection id="pgblksec" title="Information" columns="2">
                <apex:inputField value="{!Employee__c.Employee_Segment_Ineligible_Under_Plan__c}" onchange="calculatedSubtotal()" id="employeeSIUP" style="width:80%"></apex:inputField>
                <apex:inputField value="{!Employee__c.Individual_Income_Reported_Via_IRS__c}" onchange="calculatedSubtotal()" id="individualIRVI" style="width:80%"></apex:inputField>
                <apex:inputField value="{!Employee__c.Calculated_Subtotal__c}" id="calTotal" style="width:80%"></apex:inputField>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
    
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
    <script type="text/javascript">
        var calculatedSubtotal = function() {
            $( "[id*='calTotal']" ).attr( "readonly", "true" );
            
            var empSIUPVal  = $( "[id*='employeeSIUP']" ).val();
            var indvIRVI    = $( "[id*='individualIRVI']" ).val();
            
            var total = parseFloat( empSIUPVal ) + parseFloat( indvIRVI );
            if( !isNaN( total ) ) {
                $( "[id*='calTotal']" ).val( total );
            }
        };
        
        calculatedSubtotal();
    </script>
</apex:page>
Hope this helps.

Kindly mark this as solved if the reply was helpful.

Thanks,
Nagendra