title: Adding a (automatic) date field in data entry form using Sharepoint Designer 2010
body: <p>I have a Sharepoint data entry Form for my List (Inspection Table), which has a field called "Date Entered". I want to automatically populate today's date and time when a user clicks on "Add new entry", as I want to use that as audit data.</p>
  
  <p>Now, I wanted to use java script (as after research, this seems the most straight forward way to do so), so I added the following to the NewForm.aspx page:</p>
  
  <pre><code>&lt;asp:Content ContentPlaceHolderId="PlaceHolderAdditionalPageHead" runat="server"&gt;
  &lt;script language="javascript" type="text/javascript"&gt;
  var today = new Date(); 
  var dd = today.getDate(); 
  var mm = today.getMonth()+1; //January is 0! 
  var yyyy = today.getFullYear(); 
  if(dd&lt;10)
  {dd='0'+dd;} 
  if(mm&lt;10)
  {mm='0'+mm;} 
  var formattedToday = mm+'/'+dd+'/'+yyyy;
  alert(formattedToday);
  document.getElementById('&lt;%=  ((TextBox)this.onetIDListForm.FindControl("ff10_1")).ClientID %&gt;').value = formattedToday;
  &lt;/script&gt;
  &lt;/asp:Content&gt;
  </code></pre>
  
  <p>The <code>alert(formattedToday);</code> is just to test if the java script is picked up of course and will be removed in later stage.</p>
  
  <p>Ok.. I get the popup, so the value is calculated correctly and java script works. The problem I have, is putting this value to the "Date Entered" field.</p>
  
  <p>What would be the correct method to call the document.getElementByID?</p>
  
  <p>I have tried multiple variations:</p>
  
  <pre><code>document.getElementById('&lt;%=  ((TextBox)this.onetIDListForm.FindControl("ff10_1")).ClientID %&gt;').value = formattedToday;
  </code></pre>
  
  <p>Or..</p>
  
  <pre><code>document.setElementById("Date Entered").value = formattedToday;
  </code></pre>
  
  <p>Or..</p>
  
  <pre><code>document.setElementById("ff10_1").value = formattedToday;
  </code></pre>
  
  <p>Can somebody point me to the correct format, or the way to make this work?</p>
  
  <p>Next to the script above, I think I need the Form field "Date Entered" behavior (enable view) to be set to "False" but that is out of scope at the moment.</p>
  
  <p>Thanks,
  Chris</p>