This solution lets you pull in additional information from another list based on a lookup column. It works much in the same way as the SP2010 / 2013 lookup column setting “Add a column to show each of these additional fields” found in the list settings > Change column. The difference is that this one works in NewForm and EditForm as well, where the built-in SharePoint feature only works in DispForm.
This image shows NewForm
All the highlighted fields have been pulled in based on the lookup column. Please note that these fields are not stored in the current item, but are shown when viewing the form in NewForm, DispForm or EditForm.
I have updated the code to use spjs-utility.js and thus support newer versions of jQuery and browsers other than IE. The only new feature I have added, is support for displaying the information in DispForm.
I have NOT changed the function call to ensure backwards compatibility with the older solution.
This solution is in fact only tested in SP 2007, but should work for SP2010/2013 as well. Please post any findings below.
Use this code in a CEWP below NewForm, DispForm and EditForm:
How to access the values after they have been pulled in to the table
Each of the TDs with the values have been assigned an ID like this:
The green part is the FieldInternalName of the lookup column, and the red part is the FieldInternalName of the field that the info is pulled from.
To get the value from this field, you use a standard jQuery selector like this
var myFieldVal = $("#MyLookupColumn_TextField1").html(); alert(myFieldVal);
Ask if anything is unclear,