0

I am new to SharePoint and need some assistance. I have a webpage written in normal HTML and JavaScript with an IFRAME that contains a SharePoint page. When the webpage loads, it contains the user's name in a hidden field. I am trying to make it so when a person clicks a button on the webpage it sets the People Picker to the text input's value from my webpage (the user's name). I tried to pull the ID of the textarea element of the SharePoint People Picker in the IFRAME and use normal j Query to set the value of the textarea of the People Picker, but it doesn't work. Any ideas? I am trying to input it on NewForm.aspx.

In the Webpage, I have a hidden input with the id 'hiddenUser' that pulls the SharePoint user's name in this format = 'Jackson, Joseph'. That works fine; although, I am not sure if that is the best way to do it. Assuming the hiddenUser input has a value, this is what I was using to try and set the People Picker:

var userPosting = $('#hiddenUser').val(); $('#newForm').contents().find('#ctl00_m_g_ffa4fb44_5605_472f_b10f_ba47d0267de5_ctl00_ctl04_ctl19_ctl00_ctl00_ctl04_ctl00_ctl00_UserField_downlevelTextBox').text(userPosting);

'newForm' is the ID of the IFRAME on my webpage. I also tried .val instead of .text and it didn't work. Any suggestions? There are multiple People Pickers on the SharePoint form.

1 Answers1

0

It's possible for an embedded page in an iframe to talk to the containing parent page, but the parent page can't talk to the child unless the child explicitly allows it. JavaScript in the embedded page can refer to a parent object.

Check out this similar answer:

There is a way. When the page in the iframe loads, have it do the following parent.childGetElementById = function (id) {return document.getElementById(id);} parent.childLoaded();

This will make a function in the global scope of the parent page (that contains the iframe). Then in the parent, just have the following function childLoaded() {var dom = childGetElementById('someid');}

This is along as you have control of the page your loading into the iframe... if you do not, you are out of luck.

Community
  • 1
  • 1
Thriggle
  • 7,009
  • 2
  • 26
  • 37
  • I am able to set other options in the child (iframe) from the parent, for example checkmark boxes. This works for checkmark boxes: $('#newForm').contents().find('#xxxxx').prop('checked', true);. I am just having trouble modifying the People Picker from the parent. Am I missing something? – nicholasm5581 Oct 19 '15 at 17:22