SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to set default value of "End Time" field in Calender NewForm.aspx page. Here is my code:

var txtDate = $("#" + $("label:contains('End Time Date')").attr("for"));
var cboHours = $("#" + $("label:contains('End Time Hours')").attr("for"));
var cboMinutes = $("#" + $("label:contains('End Time Minutes')").attr("for"));

cboHours.val("9 AM");

Through break point, I can see that values are properly set on respective dropdowns of "End Time" field, but after my JavaScript code, SharePoint change back those values to +1 hour of current selected "Start Time". If "Start Time" value is "1/4/2013 6:30 AM", SharePoint change back the value of "End Time" to "1/4/2013 7:30 AM".

I am wondering if there is any to set value of "End Time" through Javascript. Or else, if there is any Javascript hack to remove dependency between "Start Time" and "End time"?

share|improve this question
up vote 3 down vote accepted

In order to init form fields on the client side make sure that your code is executed after page is loaded, for example place your call into SharePoint specific function _spBodyOnLoadFunctionNames

function initEndDateEvent()
   var txtDate = $("#" + $("label:contains('End Time Date')").attr("for"));
   var cboHours = $("#" + $("label:contains('End Time Hours')").attr("for"));
   var cboMinutes = $("#" + $("label:contains('End Time Minutes')").attr("for"));

   cboHours.val("9 AM");


New form for Calendar for this case will look like this

enter image description here

share|improve this answer
Awesome! It just worked. Appreciate your help. – Firoz Ansari Jan 8 '13 at 15:32
I'm glad it helped :) – Vadim Gremyachev Jan 8 '13 at 15:35

You can disable modal windows using

Library/List Settings > Advanced Settings > "Launch Forms in a Dialog" > No

Turns out there is a script that you can load for your newform.aspx page (that being the page you gets when not using modal windows) that will handle the start and end times using jquery.



share|improve this answer
Thanks Mike. I do want to open the form as modal dialog box. Is there anyway I can disable that Javascript code which drive "End Time"? – Firoz Ansari Jan 7 '13 at 18:21
You may have to create your own new modal dialog window.… – Mike Jan 7 '13 at 19:17

When are you firing your code? I often use $("#OnetListID").ready() when trying to change fields when the page loads.

share|improve this answer
I just tried $("#OnetListID").ready(), it still showing same issue. – Firoz Ansari Jan 7 '13 at 19:28
Sorry, I just listed that out of memory. The wrapper function should be $("#onetIDListForm").ready() Also be sure to put this on the page loaded by the modal dialog – Blue Murphy Jan 7 '13 at 20:55
No luck with $("#onetIDListForm").ready(). I appreciate your help. – Firoz Ansari Jan 8 '13 at 14:54

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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