I’m building a Visualforce page in which a form needs to be filled in. In the form there is a Lookup field to lookup an Account. After you’ve done this an AJAX calls should be done to update something else. The id of the selected item must be passed to this JS function.
The code for the inputField looks like this:
<apex:inputField value="{!Account}" id="acct" onchange="doSomething(this.value);" />
So in the code above, doSomething() must get the id as an argument. In the current form, this.value contains the name of the selected item. Can I get the id, and if so, how?
Inspect the generated markup with Firebug or similar tool. Each lookup field consists of several input fields (one is visible, rest is hidden).
(in my example I’ve explicitly put
idattribute on all tags from the top (apex:page, form block, section and finally the input field. If you don’t do it you’ll get autogenerated names).So what you need to do:
thisgo to parent tag (this.parentNodeshould work in plain DOM, of course jQuery is always advised 😉)acct_lkoldProbably “previousSibling” will work too?