This topic is locked

Add days to an existing date field

10/22/2021 1:22:26 AM
PHPRunner General questions
Mark Kramer author

I am trying to take the "Date Completed" field and add the value from $da2 to give me a due date "Due" field. I have tried so many different attempts that my mind is scrambled.. Any suggestions would be greatly appreciated. I have been all over the web and every example falls short. Here is my code.
//start of code
var $cycle = Runner.getControl (pageid, 'Maint Cycle in Days');
var d4 = Runner.getControl (pageid, 'Due');
var d5 = Runner.getControl(pageid,'Date Completed');
var d8 = Runner.getControl(pageid, 'Maint Cycle in Days');
var $da2;

function func() {
if ($cycle.getValue()=="1 Day"){ ($da2=1);

if ($cycle.getValue()=="3 Day"){ ($da2=3);
if ($cycle.getValue()=="15 Day"){ ($da2=15);
if ($cycle.getValue()=="30 Day"){ ($da2=30);

if ($cycle.getValue()=="60 Day"){ ($da2=60);
if ($cycle.getValue()=="90 Day"){ ($da2=90);
if ($cycle.getValue()=="120 Day"){ ($da2=120);
if ($cycle.getValue()=="180 Day"){ ($da2=180);
if ($cycle.getValue()=="365 Day"){ ($da2=365);

// set date
var userSelectedDate = new Date(Runner.getControl(pageid,'Date Completed'));
var mycustomdate = new Date();
mycustomdate.setDate(userSelectedDate.getDate() +$da2);

d5.on('change', func);
d8.on('change', func);

Thanks in advance

admin 10/22/2021

I can tell that var $cycle is incorrect. Variable names start with the dollar sign in PHP only, you cannot do this in Javascript.

You also need to provide some insight on what exactly is not working, what errors you getting etc. Start by watching this video: