This is the code ive put together so far. I am running into the error that event.value is NOT a function.
i would appreciate any help to correct the code. This code is for an editable pdf that is in a flowed container. The table has new instance added with the click of a button so the code copies down with each new addition to the table.
Code is Below:
if (this.getField("timeout").valueAsString.length === 0 || this.getField("timein").valueAsString.length === 0) {
event.value = "0";
}
else{
var timefinished = this.getField("timeout").valueAsString.length;
var timestarted = this.getField("timein").valueAsString.length;
var difflnMilliSeconds = Math.abs(timefinished - timestarted )/1000;
// calculate hours
var hours = Math.floor(difflnMilliSeconds / 3600) % 24;
difflnMilliSeconds = hours *3600;
// calculate minutes
var minutes = Math.floor(difflnMilliSeconds / 60) % 60;
difflnMilliSeconds = minutes * 60;
// set field value to the difference
event.value = hours + ":" + minutes;
}
Views
Replies
Total Likes
In which event you are calling the script? Are you setting the value for any field?
The event for the if statement is a data entry into the "timein" or "timeout" field. The calculation should run for the time when the "timeout" field data is entered. When the calculation is run it sets the value of the "total" field which has the formula in it.
https://helpx.adobe.com/in/livecycle/kb/xfa-event-change-javascript-livecycle.html
see if it help otherwise your form need to check.
I'm not using xfa.
how can I attach the form for review?
This page says .pdf not supported.
use acrobat send to send the file and attach the download link here
Attached is the form that I need help with
https://acrobat.adobe.com/id/urn:aaid:sc:VA6C2:d3b75ea6-6977-4bde-bb80-e159e910ed36
This will be your basic calculation code for hours in javascript. Hope this will help.
form1.Body.labor_cost.Row1.total::calculate - (JavaScript, both)
if (timein.rawValue == 0 || timein.rawValue == null || timeout.rawValue == 0 || timeout.rawValue == null){
this.rawValue=0;
}
else{
var timefinished = timeout.rawValue;
var timestarted = timein.rawValue;
this.rawValue = timefinished - timestarted;
}
I appreciate your help and would appreciate your help in finishing the code.
The code provided doesn't work with minuets just whole hours.
Is there a way to make the more complex code originally provided in the form work to display the hours in whole numbers and the minuets in a decimal?
I have played with it a bit and have got the if statement to return zero however the bottom half of the script won't calculate the hours.
if (timein.rawValue == 0 || timein.rawValue == null || timeout.rawValue == 0 || timeout.rawValue == null){
this.rawValue=0;
}
else{
var timefinished = (timeout.rawValue);
var timestarted = (timein.rawValue);
var difflnMilliSeconds = Math.abs(timefinished - timestarted )/1000;
// calculate hours
var hours = Math.floor(difflnMilliSeconds / 3600) % 24;
difflnMilliSeconds = hours *3600;
// calculate minutes
var minutes = Math.floor(difflnMilliSeconds / 60) % 60;
difflnMilliSeconds = minutes * 60;
// set field value to the difference
this.rawValue = hours + "." + minutes;
}
Here you go..
if (timein.rawValue == 0 || timein.rawValue == null || timeout.rawValue == 0 || timeout.rawValue == null){
this.rawValue=0;
}else{
var startTime= new Date("01/01/2007 " + timein.rawValue);
var endTime= new Date("01/01/2007 " + timeout.rawValue);
var timeDiff = getTimeDifference(startTime, endTime);
this.rawValue = timeDiff
}
function getTimeDifference(startTime, endTime) {
var difference = endTime - startTime;
var differenceInMinutes = difference / 1000 / 60;
var hours = Math.floor(differenceInMinutes / 60);
if (hours < 0) {
hours = 24 + hours;
}
var minutes = Math.floor(differenceInMinutes % 60);
if (minutes < 0) {
minutes = 60 + minutes;
}
var hoursAndMinutes = hours + ":" + (minutes < 10 ? '0' : '') + minutes;
return hoursAndMinutes;
}
Views
Likes
Replies
Views
Likes
Replies