
Hi Sonali <apex:inputField value="{!SomeLookupField}" onchange="getMethod()"/> in above tag onchange is a javascript event.So directly we cant call controller methods from javascript.so instead of that we will use actionsupport or action function. plz check sample code below
<apex:page controller="exampleCon">
<apex:form>
<apex:outputpanel id="counter">
<apex:outputText value="Click Me!: {!count}"/>
<apex:actionSupport event="onclick"
action="{!incrementCounter}"
rerender="counter" status="counterStatus"/>
</apex:outputpanel>
<apex:actionStatus id="counterStatus"
startText=" (incrementing...)"
stopText=" (done)"/>
</apex:form>
</apex:page>
/*** Controller: ***/
public class exampleCon {
Integer count = 0;
public PageReference incrementCounter() {
count++;
return null;
}
public Integer getCount() {
return count;
}
}
please let me know if you have any questionsThanksVaraprasad<apex:page standardController="Contact" extensions="ActionSupport">
<apex:form >
<apex:pageBlock id="Change">
<apex:pageBlockSection >
<apex:inputField value="{!Contact.lastname}"/>
<apex:inputField value="{!Contact.AccountID}">
<apex:actionSupport action="{!Testit}" event="onchange" reRender="Change"/>
</apex:inputField>
<apex:inputField value="{!Contact.Phone}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
public class ActionSupport {
public Contact ConRec;
public ActionSupport(ApexPages.StandardController controller) {
ConRec=(Contact)controller.getRecord();
//ConRec.phone='99999999999';
}
public void testit()
{
system.debug('Account ID===========>'+ConRec.accountid);
Account varacc=[select id,name,phone from Account where id=:ConRec.accountid];
ConRec.phone=varacc.phone;
}
}