I have a VF page that contains 2 text fields. What I am trying to do is populate Field2 with the value from Field1 when Field1 is entered, but do so in real time (i.e., using actionRegion & actionSupport). I do have a custom controller on the page. Can anyone help with how to do this? Thanks.

VF Page Controller:

public with sharing class VF_Controller_CancelCreateCampaign{

    public string Budget_Name__c {get; set;}
    public string Use_Budget__c {get; set;}

public Campaign_Create_Request__c CCR;

    public VF_Controller_CancelCreateCampaign(ApexPages.StandardController myController){
        this.CCR = (Campaign_Create_Request__c)myController.getRecord();

    public PageReference saveInit() {

            update CCR;

        catch(DmlException ex){

        PageReference tempPage = new PageReference('/apex/VF_CampaignCreate_View?id=' + CCR.Id);
        return tempPage ;

    public PageReference delInit() {
        delete CCR;

        PageReference tempPage = new PageReference('/' + CCR.Opportunity__r.Id);
        return tempPage ;

    public void BudgetName(){
        CCR.Use_Budget__c = CCR.Budget_Name__c;
  • use javascript? Commented Jul 23, 2016 at 2:04
  • what you have tried so far? show us our code. Commented Jul 23, 2016 at 8:30

2 Answers 2


I have tried this logic and it is perfectly working.

Sample Page

<apex:page controller="sampleController" id="mypage">
<apex:form >            
    <apex:inputText value="{!temp}" id="field1">
        <apex:actionSupport event="onkeyup" reRender="Details" action="{!passValueToController}"/>
    <apex:outputPanel id="Details">            
        <apex:inputText value="{!temp1}" id="field2"/>


public class sampleController{
public String temp {get; set;}
public String temp1 {get; set;}

public sampleController(){

public void passValueToController()
    temp1 = temp;
  • @JNeilan, is your problem got resolved? Commented Jul 25, 2016 at 15:07
  • I am trying your suggestion, but I get an error in my controller: Save error: Invalid identifier: Budget_Name__c. Any idea why? The field name is correct and it is a Text field.
    – J. Neilan
    Commented Jul 25, 2016 at 15:51
  • I can see you have declared Budget_Name__c as {get;set;} also using Budget_Name__c in the method, that may be conflicting Commented Jul 25, 2016 at 16:09
  • How would I resolve that?
    – J. Neilan
    Commented Jul 25, 2016 at 16:14
  • Please refer this link: developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/… . Hopefully it will help you Commented Jul 25, 2016 at 17:21

You can simply set the value in client side using javascript, rather initiating a server side round-rip action to do the same job.


<apex:page controller="AccountController">

    <apex:form >
        <apex:inputText value="{!field1}" onkeyup="setField2(this)"/>
        <apex:inputText value="{!field2}" styleClass="field2Cls"/>
        <apex:commandButton value="Print" action="{!print}" reRender="none"/>


   <script type="text/javascript">
        function setField2(field1Ele){
           document.querySelector('.field2Cls').value = field1Ele.value;


public with sharing class AccountController {
    public String field1{get;set;}
    public String field2{get;set;}

    public void print(){


You must log in to answer this question.

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