Get people picker value using Javascript

Usage: The following javascript will return the current name value of a specific people picker on a SharePoint form page
Parameter: People picker number, which is the order of the people picker on the page.
Returns: Name of the person or group, not the internal domain name.


function getPickerInputElement(pickerNo) {
var result = "";
var j = 0;
var divs = document.getElementsByTagName("DIV");

for (var i=0; i
if (divs[i].id.indexOf("UserField_upLevelDiv") > 0) {
j++;
if (j == pickerNo) {
result = divs[i];
break;
}
}
}
return result;
}

// Example: calling the function, where 1 indicates the first people picker on the page
var objPeoplePicker = getPickerInputElement(1);

// Example: getting people picker value
var employeeName = objPeoplePicker.innerText;

// Example: putting a new value to the people picker field
objPeoplePicker.innerText = "Peter Parker";

[Updated: 5/6/2012] Fixed for loop.

Spread the word. Share this post!

2 comments on “Get people picker value using Javascript”

  1. Greg Hurlman

    Your for loop is malformed; it's missing the third piece, and would never run anyway, as you're setting i to 0, and then checking if i is not 0.

Leave A Reply

Your email address will not be published. Required fields are marked *