I have a display form and a list web part just below that. When users click "add new item" on that list web part, I would like for the values to automatically be populated.

The url for the diplay form contains DispForm.aspx?ID=1, but when I open the NewForm.aspx, I would like to populate a field with that ID automatically. Can I pass that ID into the NewForm or at least into its url where I can retrieve it from there? All it seems to pass in is the list name that the display form is in.


Depending on your settings, the newform.aspx page will either open in a dialog (iframe) or open in a new page.

Here is how I address this issue in my SPELL library: I don't pass the ID in the URL, but instead I run a script on newform.aspx that follows these steps:

  1. When the new form opens, check the parent window
  2. if the parent exist (dialog), then the ID is included in window.parent.location.href
  3. If the parent does not exist (new page), then check the window.referrer

Note: in practice the newform.aspx page might be opened from more than one display forms. So you might need something more sophisticated than just splitting on ID=.

  • edit: was able to use document.referrer and window.parent.location.href which is what I think you were hinting toward. Thank you for all your help! I'm constantly finding neat tips/tricks on your blog. – user3299197 Apr 17 '14 at 1:54
  • you're welcome :-) You're right, it's parent.location.href, I have edited the answer. – Christophe Apr 17 '14 at 16:57

You can parse the ID parameter from query string in Dispform.aspx, once you have the ID value you can update "Add new Item" link and pass ID from DispForm.aspx.

Please refer to Parse Query String from Javascript to parse URL and get value from Query String.

  • 1
    Another option would be to hide the default "add new item" link and create a similar copy yourself with your custom URL generated through jQuery. – Sudhir Kesharwani Apr 16 '14 at 19:47
  • I can get the ID (I just split the location url on ID=), but how do I pass that into NewForm on the list web part? – user3299197 Apr 16 '14 at 19:53
  • The second part in my answer talks about that, update the HREF property for "Add New Item" hyperlink, make it to sp/sites/site/list/NewForm.aspx?ID=value – Sudhir Kesharwani Apr 16 '14 at 19:54
  • 1
  • Thanks for that link! It changed the href to what I needed, but the onclick action for that overrides the new url I have given it when it opens a new form on that page. I am doing some testing to see if I can figure out how to get over that. – user3299197 Apr 16 '14 at 20:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.