This topic is locked

JavaScript Calculated Field

11/29/2016 12:13:45 PM
PHPRunner General questions
E
edgarv author

Hello,
I was following the example in the Support HTML manual for calculating a field using JavaScript,
I modified the code using my fields, but this does not seem to work

when I check to see if there are any errors on the code, it does not give me an error, not sure what else could be the issue
this is the code I am using



var ctrltmin= Runner.getControl(pageid, 'DAVIESF.COMPEMP.TIMOUT');
var ctrltmout = Runner.getControl(pageid, 'DAVIESF.COMPEMP.TIMEIN');
var ctrlTotal = Runner.getControl(pageid, 'DAVIESF.COMPEMP.TOTTIM');

function func() {
ctrlTotal.setValue(Number(ctrltmout.getValue()) - Number(ctrltmin.getValue()));
};


Any help pointing me in the right direction is much appreciated

thanks!!!

C
cristi 11/29/2016

If this is all the code then you need to link your function with an js event: onclick, onchange, etc

The code is correct but it will do nothing without some trigger (push of a button or in your case an type event).
So, you need to add the event for the two variables:

ctrltmin.on('keyup', func);

ctrltmout.on('keyup', func);
E
edgarv author 11/29/2016

cristi,

thank you so very much for the reply, but all the fields are read only, I am just passing the values when the page loads it goes straight to the edit page so the employee can log in to an existing record, the employee just clicks on the save button, then the employee is redirected to a log out page looks the same as the log in except the log out time is the one that gets fill out so if I insert



ctrltmin.on('keyup', func);

ctrltmout.on('keyup', func);


would this still work? or could I do a



ctrltmin.on('load', func);

ctrltmout.on('load', func);