I want to display sum on input field dynamically . I have two input field , first one is field1 and another one is field2 . if user enter 5 in field1 then on click field2 automatically populate 25+5=30. if user enter 10 in field1 then on click field2 automatically populate 25+10=35. basically field2= 25+ field1 . i want this functionality on before saving. I don't want to use formula field.

Kindly Help! Thanks in advance.


Use This Code

<apex:page controller="TestMyPage" >
  <apex:form >
    <apex:actionFunction name="setField2Val" action="{!setField2}" rerender="block"/>
    <apex:pageBlock id="block">

      <apex:outputText value="First Value" /><apex:inputtext value="{!val1}" /> <br/>
      <apex:outputText value="First Value" />  <apex:inputtext value="{!val2}" onclick="setField2Val()"/>                   




public with sharing class TestMyPage{

  public integer val1{get;set;}
  public integer val2{get;set;}

   public void setField2(){       
       val2 = val1+25;

  • Hi Amit its not working
    – Cloud Arch
    Jul 12 '15 at 12:38
  • 1
    i have tested it , its working fine. You have to just click on second field it will show firstField+25, for ex if you put 5 in first field and than click on second field it show 30. Jul 12 '15 at 13:35
  • 1
    wait for few sec after click on second field it will not reload your page it just refresh your fields. Jul 12 '15 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.