I have created a list for scheduling meetings with an infopath form attached to fill out and submit, and the items submitted are then overlaid on a sharepoint calendar app. It is only overlaid because my manager wanted the employees to be able to click the calendar directly and add right to that date, but wants other functionality available in the infopath form.

I added the infopath form to the newitem.aspx for the calendar, and was going to use javascript to pull the value from the default calendar form that auto fills the date clicked on. I did so using this code in a script editor on the page.

<script type="text/javascript">

function setValue(idNewDate,idAutoDate) {
  var s= document.getElementById(idNewDate);
  var t = document.getElementById(idAutoDate);
  s.value = t.value;
window.onload=function() {

I then encountered that the field in the form was set, but it was set to todays date, not the date displayed. Picture of Forms and New Date

Inspecting the Start time that was autofilled, it gave this information that, even though the value displayed shows the date I clicked on the calendar, the value of the variable is todays date.

<input name="ctl00$ctl40$g_a7c0a065_f468_4e02_9827_c9816e2db457$ctl00$ctl05$ctl02$ctl00$ctl00$ctl04$ctl00$ctl00$DateTimeField$DateTimeFieldDate" 
type="text" value="8/4/2016" maxlength="45"
title="Start Time" class="ms-input" autopostback="0"

Is there some other ID I should be using to set the value in the infopath form? Or some other code I should use to set the value? Any help or advice would be much appreciated!

1 Answer 1


Even if the html shows default date as today the actual value of the element is the date that is clicked in the calendar itself.

It seems you are reading the value before the page is fully loaded. Instead of using window.onload use other options which SharePoint supports as explained in http://yakovenkomax.com/sharepoint-2013-page-load-events/

I tried below on console and it worked


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.