3

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.

1 Answer 1

2

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()"/>                   

    </apex:pageBlock>

  </apex:form>
</apex:page>

Controller

public with sharing class TestMyPage{

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

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


}
3
  • Hi Amit its not working
    – Cloud Arch
    Jul 12, 2015 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, 2015 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, 2015 at 13:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .