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.
2 comments on “Get people picker value using Javascript”