title: How to auto-populate custom field in a SharePoint Modal dialog?
body: <p>I am having some difficulty auto-populating a field in a SharePoint Modal dialog. When the dialog appears, I want the text box to be automatically set with a value. Like this: </p>
  
  <p><img src="https://i.stack.imgur.com/PY4hg.png" alt="enter image description here"></p>
  
  <p>None of these columns are default. I created a list, and then created these fields afterwards. Each are used in "Item". Then I tied the list to this dialog. Also, I went into the list settings and choose "<br>
  Allow management of content types". The default column is hidden. </p>
  
  <p>One of the problems is that I'm not sure if I need to pass the value to the options object to set the value in the text box. </p>
  
  <p>Here is the code I am currently trying. I've tested it in IE 8, 9 and 10, and also in Chrome 39. The field I want to populate when the dialog opens is always blank in each, however. </p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
  ExecuteOrDelayUntilScriptLoaded(getWebUserData, "sp.js");  
  var context = null;  
  var web = null;  
  var currentUser = null;  
  
  function getWebUserData() 
  {  
      context = new SP.ClientContext.get_current();  
      web = context.get_web();  
      currentUser = web.get_currentUser();  
      currentUser.retrieve();  
      context.load(web);  
      context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod), Function.createDelegate(this, this.onFailureMethod));  
  }    
  
  function ContactUsOpenDialog(strPageURL)
  {
      var userObject = web.get_currentUser(); 
      var options = 
      {
          title: "Contact Us",
          width: 750,
          height: 550,
          url: strPageURL
          //args: "Subject"
      };
  
      $(document).ready(function(){
      $('input[name*="Subject"]').val("The field is set for the user");
      })
  
      // I also tried this
      //$("input[Item='Subject']").val("The field is set for the user");
  
      SP.UI.ModalDialog.showModalDialog(options);
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>This is how I render the dialog via html: </p>
  
  <pre><code>&lt;a href="#" onclick="javascript:ContactUsOpenDialog(&amp;#39;http://site...com/Lists/Contact Us/NewForm.aspx?RootFolder=&amp;#39;);"&gt;
  &lt;p class="fontStyle"&gt;Contact Us&lt;/p&gt;
  &lt;/a&gt;​
  </code></pre>
  
  <p>Any ideas what is wrong, or how I can auto-populate the Subject custom field in the dialog? </p>