Copy link to clipboard
Copied
Hi,
I got this script of calculation of time
on this community and i modified it to suit my form everything is working fine.. but when i reset the form .. everything should be blank or 0 but the calculated field still keeps the last calculated value;
Here is the script (run through calculate tab):
var cStartDate = this.getField("Date").valueAsString;
var cStartTime1 = this.getField("IN_TIME1").valueAsString;
var cStartDateFormat = "dd-mmm-yyyy";
var cStartTimeFormat = "h:MM tt";
cStartTime1 = AdjustMidnight(cStartTime1);
var cEndDate = this.getField("Date").valueAsString;
var cEndTime1 = this.getField("OUT_TIME1").valueAsString;
var cEndDateFormat = "dd-mmm-yyyy";
var cEndTimeFormat = "h:MM tt";
cEndTime1 = AdjustMidnight(cEndTime1);
event.value = 0;
if(cStartDate != "" && cStartTime1 != "" && cEndDate != "" && cEndTime1 != "")
{
var t1 = DateTime2Min(cEndDateFormat + " " + cEndTimeFormat, cEndDate + " " + cEndTime1) - DateTime2Min(cStartDateFormat + " " + cStartTimeFormat, cStartDate + " " + cStartTime1);
}
var cStartDate = this.getField("Date").valueAsString;
var cStartTime2 = this.getField("IN_TIME2").valueAsString;
var cStartDateFormat = "dd-mmm-yyyy";
var cStartTimeFormat = "h:MM tt";
cStartTime2 = AdjustMidnight(cStartTime2);
var cEndDate = this.getField("Date").valueAsString;
var cEndTime2 = this.getField("OUT_TIME2").valueAsString;
var cEndDateFormat = "dd-mmm-yyyy";
var cEndTimeFormat = "h:MM tt";
cEndTime2 = AdjustMidnight(cEndTime2);
event.value = 0;
if(cStartDate != "" && cStartTime2 != "" && cEndDate != "" && cEndTime2 != "")
{
var t2 = DateTime2Min(cEndDateFormat + " " + cEndTimeFormat, cEndDate + " " + cEndTime2) - DateTime2Min(cStartDateFormat + " " + cStartTimeFormat, cStartDate + " " + cStartTime2);
}
event.value = t1 + t2;
Try this:
var t1 = "";
var t2 = "";
var cStartDate = this.getField("Date").valueAsString;
var cStartTime1 = this.getField("IN_TIME1").valueAsString;
var cStartDateFormat = "dd-mmm-yyyy";
var cStartTimeFormat = "h:MM tt";
cStartTime1 = AdjustMidnight(cStartTime1);
var cEndDate = this.getField("Date").valueAsString;
var cEndTime1 = this.getField("OUT_TIME1").valueAsString;
var cEndDateFormat = "dd-mmm-yyyy";
var cEndTimeFormat = "h:MM tt";
cEndTime1 = AdjustMidnight(cEndTime1);
event.value = 0;
i
...
Copy link to clipboard
Copied
Hi,
How are you resetting the form? a button, custom script.
Regards
Malcolm
Copy link to clipboard
Copied
I tried 3 methods of resetting but still the last calculated value remains... i don't want to make a RESET BUTTON to reset the field .... i want if the user deletes the value individually the calculated field resets itself..
1. RESET the form via inbuilt adobe acrobat > CLEAR FORM
2. INDIVIDUALLY deleting all the values from each field.
3. Made a button and through ACTION tab > RESET A FORM ... this also doesnot work
None of them resets the calculated field.
Copy link to clipboard
Copied
Hi,
Are you able to share the document? as that should just work.
And which version of Acrobat are you using?
Regards
Malcolm
Copy link to clipboard
Copied
Below is the screenshot of my Adobe version
Copy link to clipboard
Copied
Here is the link to the file:
https://www.dropbox.com/s/ur2qi00v1kd9unm/PDF%20Time%20calculation.pdf?dl=0
Copy link to clipboard
Copied
Have you included in your form a function called 'AdjustMidnight'?
Are you getting any earnings in the Acrobat JavaScript console?
Have you checked the field calculation order for the form?
Copy link to clipboard
Copied
yes i have included 'adjust Midnight function":
function AdjustMidnight(cValue)
{
if(/^(12)(:\d{2})[ ](am)$/.test(cValue.toLowerCase()))
{
cValue = "00" + RegExp.$2 + RegExp.$3;
}
return cValue;
}
in console window.. it give something : Type Error : f is null
There is only one calculated field nothing to bother about calculation order
Copy link to clipboard
Copied
Attached is the full document level script .. i got this from this community :
function Scand(cFormat, cValue)
{
var oField = util.scand(cFormat, cValue);
if(oField == null)
{
app.alert("Error converting date time string of " + cValue + " with a format of " + cFormat, 1, 0);
}
return oField;
}
function AdjustMidnight(cValue)
{
if(/^(12)(:\d{2})[ ](am)$/.test(cValue.toLowerCase()))
{
cValue = "00" + RegExp.$2 + RegExp.$3;
}
return cValue;
}
function DateTime2Min(cFormat, cValue)
{
oDate = Scand(cFormat, cValue);
return Math.floor(oDate.getTime()/(1000*60));
}
Copy link to clipboard
Copied
Here is the link to the File:
https://www.dropbox.com/s/ur2qi00v1kd9unm/PDF%20Time%20calculation.pdf?dl=0
Copy link to clipboard
Copied
Try this:
var t1 = "";
var t2 = "";
var cStartDate = this.getField("Date").valueAsString;
var cStartTime1 = this.getField("IN_TIME1").valueAsString;
var cStartDateFormat = "dd-mmm-yyyy";
var cStartTimeFormat = "h:MM tt";
cStartTime1 = AdjustMidnight(cStartTime1);
var cEndDate = this.getField("Date").valueAsString;
var cEndTime1 = this.getField("OUT_TIME1").valueAsString;
var cEndDateFormat = "dd-mmm-yyyy";
var cEndTimeFormat = "h:MM tt";
cEndTime1 = AdjustMidnight(cEndTime1);
event.value = 0;
if(cStartDate != "" && cStartTime1 != "" && cEndDate != "" && cEndTime1 != "")
{
t1 = DateTime2Min(cEndDateFormat + " " + cEndTimeFormat, cEndDate + " " + cEndTime1) - DateTime2Min(cStartDateFormat + " " + cStartTimeFormat, cStartDate + " " + cStartTime1);
}
var cStartDate = this.getField("Date").valueAsString;
var cStartTime2 = this.getField("IN_TIME2").valueAsString;
var cStartDateFormat = "dd-mmm-yyyy";
var cStartTimeFormat = "h:MM tt";
cStartTime2 = AdjustMidnight(cStartTime2);
var cEndDate = this.getField("Date").valueAsString;
var cEndTime2 = this.getField("OUT_TIME2").valueAsString;
var cEndDateFormat = "dd-mmm-yyyy";
var cEndTimeFormat = "h:MM tt";
cEndTime2 = AdjustMidnight(cEndTime2);
event.value = 0;
if(cStartDate != "" && cStartTime2 != "" && cEndDate != "" && cEndTime2 != "")
{
t2 = DateTime2Min(cEndDateFormat + " " + cEndTimeFormat, cEndDate + " " + cEndTime2) - DateTime2Min(cStartDateFormat + " " + cStartTimeFormat, cStartDate + " " + cStartTime2);
}
event.value = t1 + t2;