Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

share|improve this question
add comment

2 Answers

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

share|improve this answer
    
Thank Eric for pointing me to the PreSaveAction. –  spStacker Feb 1 '12 at 22:14
    
Never heard about this function, but it's really useful, thanks –  Kai Feb 2 '12 at 7:19
    
Me either but thanks for this savior action :D –  Falak Mahmood Feb 2 '12 at 9:05
    
Hi Eric, i have updated the question –  spStacker Feb 2 '12 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. –  PirateEric Feb 2 '12 at 14:36
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

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.