6

I have a visualforce page to do some CRUD operations on a custom object, which contains a lookup field to the account. I need to do some client side validations with javascript based on the Id of the lookup field.

Can someone explain how could I access the hidden Id field of the lookup field

have seen some {!$Component.accountLookup} sort of a soulution being explained in sevaral posts though, I do not understand how this works.

Thanks in-advance

5

During creation of the visual force, you can add an id attribute to your lookup field. Let say for example your id="lookupId". You can access the hiddent lookup id like this: $('[id$="lookupId_lkid"]').val(); . Just put a _lkid in the end of your id. Hope this is what you're looking. As a summary the code something look like this.

<apex:inputField value="{!o.sampleValue__c}" styleClass="theLookup" required="true" id="lookupId"> 

JS:

var theAccountId = $('[id$="lookupId_lkid"]').val();
| improve this answer | |

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.