I am working on customizing the sharepoint list form (newform.aspx). So soon as the user opens the new form I want the Odate coloumn (date and time) to be filled automatically with the current date and time and get disabled. It is taking the current date but I am not sure how to set the time. Below is the code, any suggestions?

    $(document).ready(function() {
    var date = new Date();
    var datinformat = date.getMonth()+1 + "/" + date.getDate() + "/" + date.getFullYear();
$("input[title ='Origin Date']").val(datinformat);

    $("input[title='Origin Date']").attr('disabled','disabled');

[Update]: enter image description here Hi Eric, when i changed default value of the field to today -It shows hour properly,but in the minutes section is shows 0 even if it is 15 mins or any number - and from the image when when i change the setting of the date field to include the time as well from the image i got hour and mins dropdwn...but even if the Odate field is disable the hour and mins dropdown still remain selectable..any suggestions

2 Answers 2


Can't you just set the default value for the field to be [Today]?

You'll also need to utilize the PreSaveAction to reenable the Odate column or it won't get saved. http://wael-abbas.blogspot.com/2009/02/sharepoint-presaveaction.html

  • Thank Eric for pointing me to the PreSaveAction.
    – SandeshR
    Feb 1, 2012 at 22:14
  • Never heard about this function, but it's really useful, thanks Feb 2, 2012 at 7:19
  • Me either but thanks for this savior action :D Feb 2, 2012 at 9:05
  • Hi Eric, i have updated the question
    – SandeshR
    Feb 2, 2012 at 14:30
  • The date and time fields are separate inputs so you'd have to disable those too. And since they have predefined values, you can set those as needed. Feb 2, 2012 at 14:36

Maybe just add the time to the string you are building? The Date object has time methods as well... You do have to make sure that the underlying field is DateTime and not simply Date as that will truncate the time back off when it saves

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.