Hi Guys,
I am trying to create a javascript onLoad event on an add page to calculate on the fly when a students course has expired.
So far,
I have DATE field called "training_Date"
I also have an INT field called "duration_In_Days" (this field contains the amount of days until the course will expire i.e. 190).
My aim is to calculate the future date of which a students course will expire by taking the "training_Date" value i.e. 01/01/2001 and adding the value form the "duration_In_Days" i.e. 250 which would give me a date of expiry
I plan to display the results of this calculation in a "expiry_Date" field.
Using various examples I have cobbled together the following event with no Luck!
I would love to hear your thoughts, Is this possible?
var ctrlDuration = Runner.getControl(pageid, 'duration_In_Days');
ctrlDuration.on('change', function(e){
var ctrlExpiry = Runner.getControl(pageid, 'expiry_Date');
var ctrlTd = Runner.getControl(pageid, 'training_Date');
var d1 = new Date(this.getValue());
var d2 = new Date(ctrlTd .getValue());
var millisecondsPerDay = 1000 * 60 * 60 * 24;
var millisBetween = d1.getTime() - d2.getTime();
var days = millisBetween / millisecondsPerDay;
function func() {
ctrlExpiry .setValue(Number(ctrlTd.getValue()) + Number(ctrlDuration.getValue()));
};
ctrlDuration.on('keyup', func);
ctrlExpiry.on('keyup', func);
});
Best wishes,
J