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

1 Answer 1


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"> 


var theAccountId = $('[id$="lookupId_lkid"]').val();

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .