I need to fill a look up value with query string parameter in custom new form in sharepoint 2013. what should I do?

1 Answer 1


Use javascript by adding a Content Editor to the page or adding it to the markup itself. I did something similar, picked up ContactId from Query String. Picked up this code from here

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

    <script type="text/javascript">

    jQuery(document).ready(function($) {

        //get the Contact ID from they query string
        var contactId = getParameterByName("contactId");

        //Set the corresponding Lookup field value to the Contact ID
        $("select[title='Contact Name']").val(contactId);    

        //use this line to disable the lookup field selection
        $("select[title='Contact Name']").attr('disabled','disabled')

        //use this line to hide the lookup field and label entirely
        //$("select[title='Contact Name']").closest("tr").hide();            

    function getParameterByName(name)
      name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
      var regexS = "[\\?&]" + name + "=([^&#]*)";
      var regex = new RegExp(regexS);
      var results = regex.exec(window.location.href);
      if(results == null)
        return "";
        return decodeURIComponent(results[1].replace(/\+/g, " "));



  • I test it several Time in my publishing site but it doesn't work :(
    – Melika
    May 25, 2015 at 19:40
  • 1
    This is working code. Make sure that the id's are right. 1. Use the inspectors in IE, chrome or (firefox + firebug) to check the title attribute. 2. You can debug javascript by adding breakpoints and stepping through the code in the browser 3. Check the values of the statements by copy pasting them into Javascript console in the browser. May 25, 2015 at 19:50
  • 1
    And make sure you change line 1 to a location where jquery.min.js exists May 25, 2015 at 20:04
  • Updated the jquery src reference to google cdn. Good catch Per Jakobson May 25, 2015 at 20:13
  • What is getParameterByName function usage?
    – Melika
    May 25, 2015 at 21:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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