I am trying to auto populate the value of lookup field to text field in the visualforce page. As soon as I select the value of lookup field from the list the value as it get populated in the lookup field also it need to get populated in the text field which I have created in the visualforce page. Can I achieve this functionality ?

Here Daily_Record__c is my custom object I want to auto populate the value of <apex:inputfield value="{!Daily_Record__c.Username__c}"/> in to the <apex:inputText value="{!strAccSearchString}"/> so what should I do ?

apex code :-

 <apex:page Standardcontroller="Daily_Record__c" extensions="ctrlSearch">
<apex:form >  
  <apex:inputfield value="{!Daily_Record__c.Username__c}"/>
    <apex:inputText value="{!strAccSearchString}"/>>
     <apex:commandButton value="Search" action="{!SearchAccountRec}"/>       
      <apex:pageBlock rendered="true" title="Search Result">
        <apex:pageBlockTable value="{!lstAccount}" var="acc">
         <apex:column >
          <apex:facet name="header">Name</apex:facet> 
        <apex:outputLink value="/{!acc.id}">{!acc.Username__c} 
            <apex:column >
    <apex:pageBlock rendered="{!If(lstAccount.size==0 && isResultDisplay == 
          true,true,false)}" title="Search Result">           
        <apex:pageblockSection >
            <apex:outputLabel value="No Result Found"></apex:outputLabel>

There are two ways of doing this that I know of. One is to write a controller extension. If you use a controller extension, it should be straightforward to create a method that passes the lookup Id using a getter which then sets the text.

The other, which may or may not be simple depending on your skills would be to call Javascript you've written using a CommandLink via OnClick. Your JS will then need to take the value of !Daily_Record__c.Username__c, convert it to a string and populate <apex:inputText value="{!strAccSearchString}"/> with it before calling a refresh on that section of the page (If User is pre-populated, your JS could do all this running your JS 'OnInit').

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.