Following up on my recent post about getting the current value of a People Picker on a form, today I built the JavaScript to set the value, and here it is. As usual, I’ve left in my debugging code in case you want to see how it works.
// setPickerInputElement: Set a People Picker's value using its identifier to find it in the page // Arguments: // identifier: The identifier for the instance of the fieldName (ff1, ff2, etc.) // value: Set the fieldName to this value // function setPickerInputElement(identifier, value) { 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); tags[i].innerHTML = value; break; } } }