Populating form fields dynamically from querystring parameter in lists or surveys

There is no built in support in Sharepoint to dynamically populate a form field in a survey. We had a requirement where we wanted to pass in a querystring parameter to set the value for an input field in the survey. To solve this, I used the following approach :

  1. Create the survey with your field which you want populated through querystring. Don’t specify any default value.
  2. Browse to http://SPSServer/Lists/YourSurvey/NewForm.aspx
  3. Do a view source. Find the name of your input field new TextField(frm,”Field_x0020_Field_x0023_“,”Please enter code#”,””), where please enter code is your field label. Grab the stuff in red color for later use.
  4. Use Frontpage 2003 to connect to your sharepoint website. Go to Lists and you will find your survey there. Expand the survey folder and open Newform.aspx
  5. Paste below code just above the closing </form> tag
  6. <script lang=”javascript”>
    var text=unescape(location.href);
    var Variable=text.substr(text.indexOf(‘?QueryStr=’)+10);
    document.getElementsByName(‘urn:schemas-microsoft-com:office:office#Field_x0020_Field_x0023_‘)(0).value =Variable;
  7. Thats it. You should be able to populate the field by change the QueryStr value in the querystring.


2 thoughts on “Populating form fields dynamically from querystring parameter in lists or surveys

  1. I have noticed that pasting the javascript in frontpage causes single quotes to be turned into special characters. You will need to manually replace those characters with single quotes yourself on 2 lines after pasting the code.

  2. Hi Nishant,
    Could you please suggest how to do this?
    For all questions in our survey we need a comment field wherein users will put their commment!!
    How do we add that extra textbox for each question.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s