cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Office 365 Forms - How can I capture the current date and time with a button

Jump to solution

I have a need to know what the JavaScript methods are for the column type date time.  Specifically I need to be able to set the date and time values via a JavaScript function

Currently I have set up buttons that I want to initializes the date and timestamps for Start and Finish

I have also set the 2 DateTime controls to JavaScript ID's of dtStart and dtFinish.

I can also successfully initialize the JavaScript via the Client Click function of the button.

var start = NWF$("#"+dtStart);
var now = new Date();
start.val(now);
alert(start.val());

When I click the Start button the result is as seen in this screen shot

I can also break down the date values and retrieve them just fine...like

var datetime = now.getFullYear()+'/'+(now.getMonth()+1)+'/'+now.getDate(); datetime += ' '+now.getHours()+':'+now.getMinutes()+':'+now.getSeconds();

What I don't know is how to set these values to the dtStart variables for each date and time value.  It doesn't appear that I can set them using the regular JavaScript methods like start.setHours().

Labels: (1)
0 Kudos
Reply
2 Replies
Workflow Hero

Re: Office 365 Forms - How can I capture the current date and time with a button

Jump to solution

Hi! Just pinging to find out whether you found a solution or still looking for it? If yes (if you found) - can you write here how you achieve that?

Regards,

Tomasz

Reply
Workflow Hero

Re: Office 365 Forms - How can I capture the current date and time with a button

Jump to solution

Hi david beayon

To get the hours and minutes drop downs populated, use the following code

var start = NWF$("#"+dtStart); 
var now = new Date();
start.val(now.getDate()+'/'+(now.getMonth()+1)+'/'+now.getFullYear());
alert(start.val());
//find the hour dropdown
var hourDropdown = start.parent().find("select[id*='DateHours']");
//find the minute drop down
var minDropdown = start.parent().find("select[id*='DateMinutes']");
//update the hours dropdown      
hourDropdown.val(now.getHours());
//get current minutes
var minutes = now.getMinutes();
//divide the current minutes by 5, round to nearest whole number
//and multiply by 5 again. this is because the minutes drop down is multiples
//of 5
minutesrounded = 5*Math.round(minutes/5);
//update the minutes dropdown
minDropdown.val(minutesrounded);

All you need to do is make sure the start.val() is in the correct date format for you

Hope the helps

Reply