You need to sign in to do that
Don't have an account?
Surya.236
Onchange function not working for lookup
Hi i have a custom visual force page , in this i was unable to use onchange event
My VF Page has Account Lookup and salesDistrict lookup ,when user chnage the account value i have to populate the accout's sales value in sales lookup field. Folowing is my code
<apex:pageBlockSectionItem helpText=" The End User’s physical location" >
Account Name:
<apex:inputField id="oppAccountId" value="{!thisOpp.AccountId}" required="true">
<apex:actionSupport action="{!populatesalesdistrict}" event="onchange" reRender="salesDistrict" status="pageStatus"/> </apex:inputField>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem helpText="Auto populated from Account; Enter if blank">
Sales District :
<apex:inputField value="{!thisOpp.Sales_District_lkup__c}" id="salesDistrict" required="true"/>
</apex:pageBlockSectionItem>
controller: Mrthod:
Public void populatesalesdistrict(){
Account thisAcc = [SELECT Id, Sales_District__c,SoldTo__c from Account where ID =: thisOpp.AccountId];
thisOpp.Sales_District_lkup__c = thisAcc.Sales_District__c;
}
What is alternate if onchange will not work for lookup fields.?
My VF Page has Account Lookup and salesDistrict lookup ,when user chnage the account value i have to populate the accout's sales value in sales lookup field. Folowing is my code
<apex:pageBlockSectionItem helpText=" The End User’s physical location" >
Account Name:
<apex:inputField id="oppAccountId" value="{!thisOpp.AccountId}" required="true">
<apex:actionSupport action="{!populatesalesdistrict}" event="onchange" reRender="salesDistrict" status="pageStatus"/> </apex:inputField>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem helpText="Auto populated from Account; Enter if blank">
Sales District :
<apex:inputField value="{!thisOpp.Sales_District_lkup__c}" id="salesDistrict" required="true"/>
</apex:pageBlockSectionItem>
controller: Mrthod:
Public void populatesalesdistrict(){
Account thisAcc = [SELECT Id, Sales_District__c,SoldTo__c from Account where ID =: thisOpp.AccountId];
thisOpp.Sales_District_lkup__c = thisAcc.Sales_District__c;
}
What is alternate if onchange will not work for lookup fields.?
I implemeted the same code you posted using actionRegion and it is working Fine.
Hope this helps.
All Answers
I think some page validation is causing some issue ,
Do the following changes in your code.
1) <apex:pagemessages id="pg" />
2) <apex:actionSupport action="{!populatesalesdistrict}" event="onchange" reRender="salesDistrict,pg" status="pageStatus"/> Then see what error you are getting when changing the lookup.
Hope this helps.
I made the changes as you said but i didnt get any error and debug logs are also not showing anything
I implemeted the same code you posted using actionRegion and it is working Fine.
Hope this helps.
Thank you for your response, there was a jquery which was stoping it's onchange property, it is working now.
Regards,
Surya