Get the value of a SharePoint People Picker field via javascript

November 2nd, 2011 | Posted by Marijn in jquery / javascript | sharepoint

The ever handsome and cunning Marc D. Anderson (I felt like giving the man credit, since I use so many of his solutions!!) saved my behind once again with a fantastic javascript!
This time I was looking to find a solution to get the value from a SharePoint people picker field via jquery.

A quick search took me to his blog where I found this code:

// Find a People Picker's value using its identifier (ff1, ff2, etc.)to find it in the page

function getPickerInputElement(identifier) {
var tags = document.getElementsByTagName('DIV');
for (var i=0; i < tags.length; i++) {
var tempString = tags[i].id;
//alert('tags[' + i + '].id = ' + tempString);
if ((tempString.indexOf(identifier) > 0) && (tempString.indexOf('UserField_upLevelDiv') > 0)){
//alert('HIT for ' + identifier + ' id=' + tags[i].id + ' value=' + tags[i].value);
var innerSpans = tags[i].getElementsByTagName("SPAN");
for(var j=0; j < innerSpans.length; j++) {
//alert('innerSpans[' + j + '].id = ' + innerSpans[j].id);
if(innerSpans[j].id == 'content') {
//alert('HIT for ' + identifier + ' id=' + innerSpans[j].id + ' innerHTML=' + innerSpans[j].innerHTML);
return innerSpans[j].innerHTML;
return null;

This works by filling in a variable with the result of the function. You give the identifier as a parameter when you call it:

var person = getPickerInputElement("ff18");

Have you ever seen an easier way to get the value of a SharePoint People Picker field via javascript ?

You can follow any responses to this entry through the RSS 2.0 You can leave a response, or trackback.

12 Responses

Leave a Reply

%d bloggers like this: