You need to sign in to do that
Don't have an account?
Developer129
Event not executing for lookup fields
Hi,
I was trying to execute an event and then correspondingly execute an action when a user selects a value for a lookup field. How can this be done?
I am using AJAX to update a part of my page depending upon the selection for the lookup field
Thanx
Are you using standard salesforce lookups and trying the onchange event?
If that is the case, it is likely because the value in the lookup is being changed through JavaScript, which doesn't cause an event to fire - events only fire when the user types in a value. The rationale behind this is that if you have a script that is changing a value, you can add your additional functionality in at that point. Unfortunately in SalesForce, the JavaScript that is making the change is hidden from you so you don't have the opportunity to do anything.
I've tended to use the onblur event, which at least fires an event when the user tabs out of the field, but it is a delayed reaction.
All Answers
With Event, do you mean any javascript event like onselect, onclick etc?
If it is so, try using onchange event.
Are you using standard salesforce lookups and trying the onchange event?
If that is the case, it is likely because the value in the lookup is being changed through JavaScript, which doesn't cause an event to fire - events only fire when the user types in a value. The rationale behind this is that if you have a script that is changing a value, you can add your additional functionality in at that point. Unfortunately in SalesForce, the JavaScript that is making the change is hidden from you so you don't have the opportunity to do anything.
I've tended to use the onblur event, which at least fires an event when the user tabs out of the field, but it is a delayed reaction.
Yeah, bob_buzzard's explanation pretty much sums it up, and this was kind of a nasty bug because there are browser differences in addition to there being several different ways to populate a lookup field (typing the value in, selecting it via a lookup, using the picklist to disambiguate, etc.) But the good news is that this was fixed pretty recently. Whenever the next major release is, you guys should see it.
Hi Jill,
When is the next major release ?
Simply add a styleClass attribute to the lookup input, for example:
<apex:inputField value="{!myContact.AccountId}" id="acct" styleClass="acct">
Then using jquery, add a change event with 'on':
$(document).on("change",".acct",function(e){...});
The event will fire after the input is filled from the lookup's javascript.