+ Start a Discussion
swapna9swapna9 

How to dispaly output filed value based on the lookup value

Hi,

 

I created two objects ObjectA : name(text),Number1(number),objB(lookup to ObjectB),objBprice(number).

                                  ObjectB:Name(text),price(number).(ex records Milk:20,

                                                                                                              Butter:50)

 

In my Visualforce page i am dispalying all objectA fileds and objectB fileds.Here i am dispalying ObjectA name as input field,Number1 is input field,

ObjB is lookup field.based on lookup value i need to autopopulate (ObjectB)"price" field value in ObjBprice (of ObjectA).

 

Can any one guide me.

 

Thanks in advance.......

Navatar_DbSupNavatar_DbSup

Hi,

 

Try the below Code Snippet as reference:

 

<apex:page controller="Lookupdemo" >

<apex:form >

 <apex:outputPanel id="fp">

<apex:outputLabel >ObjectA  Name</apex:outputLabel>

<apex:inputField value="{!ob.Name}"/><br/>

 

<apex:outputLabel >ObjectA Number1</apex:outputLabel>

<apex:inputField value="{!ob.Number1__c}"/><br/>

 

<apex:outputLabel >objB</apex:outputLabel>

<apex:inputField value="{!ob.ObjectB__c}" onchange="FillPrice(this);" /><br/>

 

  <apex:actionFunction name="calling" action="{!checkvalue}" reRender="fp" />

 

<apex:outputLabel >objBprice</apex:outputLabel>

<apex:inputField value="{!ob.objB_price__c}"/><br/>

</apex:outputPanel>

</apex:form>

  <script>

  function FillPrice(ob)

  {

      alert('calling');

      calling();

  }

  </script>

</apex:page>

 

===============Apex Controller==========

 

public class Lookupdemo

{

public ObjectA__c ob{get;set;}

public Lookupdemo ()

{

    ob=new ObjectA__c();

}

 

public void checkvalue()

{

    system.debug('____________ob.ObjectB__c________________________'+ob.ObjectB__c);

    ObjectB__c b=[select price__c from ObjectB__c where id =:ob.ObjectB__c Limit 1];

    system.debug('________b.price__c________'+b.price__c);

    ob.objB_price__c=b.price__c;

  

}

 

}

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.