Copy link to clipboard
Copied
Hi all,
I would appreciate it so much if you could help me out a little with this.
I have a starttime and endtime fields but I would like the form to auto calculate for me once these two fields have been populated.
Example:
Thank you and Regards,
James
Change the field's Format to None and use this code for the calculation (this is for the A row):
...var cStart = this.getField("Start1").value;
var cStop = this.getField("Stop1").value;
if (cStart != "" && cStop != "") {
var tStart = parseTime(cStart);
var tStop = parseTime(cStop);
var total = (tStop - tStart)/(1000*60*60);
var totalHours = Math.floor(total);
var totalMinutes = (total-totalHours)*60;
var totalHoursString = (totalHours<10) ? "0"+totalHours : ""+totalHours;
var tota
Copy link to clipboard
Copied
Are the times always in the same calendar day?
This issue was discussed many times in the past, and complete code examples have been given to answer it.
You should really try searching the forums for "time calculation", or something to that extent.
You might also find these tutorials useful:
https://acrobatusers.com/tutorials/working-with-date-and-time-in-acrobat-javascript
https://acrobatusers.com/tutorials/working-with-date-and-time-in-acrobat-javascript-part-2
https://acrobatusers.com/tutorials/working-with-date-and-time-in-acrobat-javascript-part-3
And if you want a (paid-for) tool that will set it up for you with a few clicks, check out this one I've developed:
Custom-made Adobe Scripts: Acrobat -- Calculate Time Differences in a Worksheet
Regarding your second question: Do you mean that after the user entered the four digits it will automatically jump to the next field?
Copy link to clipboard
Copied
Hi try67 ,
Thanks for being so prompt in your response.
Yes, it is the same calendar day. I have uploaded a test file that i am working on : http://www.acetraining.com.sg/pdfs/parseTime_test.pdf. It is not really working for the result. The format of the result is also not too correct as shown :
The difference should be expressed as 0130.
Any help would be appreciated.
Thanks and regards,
James
Copy link to clipboard
Copied
Change the field's Format to None and use this code for the calculation (this is for the A row):
var cStart = this.getField("Start1").value;
var cStop = this.getField("Stop1").value;
if (cStart != "" && cStop != "") {
var tStart = parseTime(cStart);
var tStop = parseTime(cStop);
var total = (tStop - tStart)/(1000*60*60);
var totalHours = Math.floor(total);
var totalMinutes = (total-totalHours)*60;
var totalHoursString = (totalHours<10) ? "0"+totalHours : ""+totalHours;
var totalMinutesString = (totalMinutes<10) ? "0"+totalMinutes : ""+totalMinutes;
event.value = totalHoursString + totalMinutesString;
}
else {
event.value = "";
}
Copy link to clipboard
Copied
Hi try67,
Thanks for your effort in helping me. Indeed, it works.
Using the same example, how do I make the form in such a way that I let the user to move from column to column automatically? For example, after entering start time (HHMM), the cursor would automatically move to the Stop time column?
I have read some articles, many of the solutions is based on the Format category having to choose Custom and Custom Keystroke Script as shown below.
However, for the example we are working on, I already set the Format to Time and set to Custom (HHMM).
Is it still possible to have the auto-tab feature and how do I achieve that?
Thanks and regards,
James
Copy link to clipboard
Copied
No, you can't combine the two things, unless you write your own custom keystroke and format scripts, which is not a simple task.
I don't think it's necessary, really. If the tab order is set correctly then the user just needs to press Tab after entering the value, and it will jump to the next field.
Copy link to clipboard
Copied