set date and time with drop down

  • 30 October 2017
  • 3 replies
  • 20 views

Badge +7

Is it possible to set a date and time field on a Nintex form based on a value in a drop down? 

If Completed in selected in the status field, we want the date and time to populate to the current date and time.

any help?

Thanks!

210205_pastedImage_1.png


3 replies

Badge +9

Try this.

NWF$(document).ready(function()
{
 NWF$('#'+dropdown).change(function()
 {
  fnSetDate();
 });
});
function fnSetDate()
{
 var dropdownvalue = NWF$('#'+dropdown).val();
 alert(dropdownvalue);
 if(dropdownvalue == 'Completed')
 {
 var fullDate = new Date();
 var twoDigitMonth = ("0" + (fullDate.getMonth() + 1)).slice(-2);
 var hours = fullDate.getHours();
 var minutes = fullDate.getMinutes();
 var currentDate = fullDate.getDate() + "/" + twoDigitMonth + "/" + fullDate.getFullYear();
 if (hours < 10) { hours = "0" + hours; }
 minutes = minutes - 2.5;
 minutes = 5 * Math.round( minutes / 5 );
 NWF$('#' + fldDateClosed).val(currentDate);

 NWF$('#' + fldDateClosed+ " + IMG + SELECT").val('10 AM');
 NWF$('#' + fldDateClosed+ " + IMG + SELECT + SELECT").val('45');
 }
}

Badge +7

Do i just put that code into the custom javascript field on the settings of the form? Does this update before or after save?

Badge +9

Yes you need to copy this code in 'Form Settings' under 'Custom JavaScript'. When you change 'Status' drop down value based on selected value this will set current date and time to your date control.210312_pastedImage_1.png

Give names like 'fldDateClosed' to 'Date control' and 'dropdown' to 'Status' like below in your control settings.

210313_pastedImage_2.png

Reply