You need to sign in to do that
Don't have an account?
pmish
Sum of two inputfield values in Visualforce Page and showing it in the third field. All the fields to be saved to object record.
Hi,
I have three fields in my VF page and user has to input two of them manually. Once both the values are entered, I need to show the Sum of both the entered values dynamically on the screen and that value must be saved to the third variable.
<apex:inputField value="{!Employee_segment_ineligible_under_plan__c}" id="eng" style="width:80%"></apex:inputField>
<apex:inputField value="{!Individual_income_reported_via_IRS__c}" id="enf" style="width:80%"></apex:inputField>
The sum should be displayed dynamically something like this and displayed without page being refreshed:
Based on your answers, the calculated subtotal is __<calculated field>__ employees.
Please Help.
Thanks!!
I have three fields in my VF page and user has to input two of them manually. Once both the values are entered, I need to show the Sum of both the entered values dynamically on the screen and that value must be saved to the third variable.
<apex:inputField value="{!Employee_segment_ineligible_under_plan__c}" id="eng" style="width:80%"></apex:inputField>
<apex:inputField value="{!Individual_income_reported_via_IRS__c}" id="enf" style="width:80%"></apex:inputField>
The sum should be displayed dynamically something like this and displayed without page being refreshed:
Based on your answers, the calculated subtotal is __<calculated field>__ employees.
Please Help.
Thanks!!
https://dfc-org-production.force.com/forums/ForumsMain?id=9060G000000Ua6zQAC
Thank you
Prady01
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 -
Thanks,
Atul Patil
Salesforce Developer
http://www.zen4orce.com
Use Javascript to add two number dynamically on change , To save that value in object you need action function which pass that value from javascript to controller and then create on method which will insert object with that sum of two values
<apex:page controller="SaveRecordController" >
<script>
function myFunction() {
var y = document.getElementById("txt1").value;
var z = document.getElementById("txt2").value;
var x = +y + +z;
document.getElementById("demo").innerHTML = x;
sumOfvalue(x);
}
</script>
<apex:form id="form">
<p>
Enter first number:
<apex:inputfield id="txt1" name="text1" onchange="myFunction();"/>
Enter second number:
<apex:inputfield id="txt2" name="text2" onchange="myFunction();"/>
</p>
<p id="demo"></p>
<apex:actionFunction name="sumOfvalue" action="{!saveRecord}">
<apex:param name="x" value="x" assignTo="{!sumOf}" />
</apex:actionFunction>
</apex:form>
</apex:page>
-------------------------------------------------------------------------------------------------
public class SaveRecordController{
public integer sumOf{get;set;}
public void saveRecord(){
Sum__c sumObj = new Sum__c();
sumObj .sumOfValue__c = sumOf;
insert sumObj;
}
}
Thanks,
Amol b Salve
Salesforce Developer
http://www.zen4orce.com