I have created a few interactive Acrobat forms in the past, mainly with basic fields such as date, time, currency and so forth. However today I have just stumbled upon the calculation field and that it may be of some use with time sheets that I am required to fill in at the workplace...
I have no idea when it comes to javascript and calculations - I can work out simple formulas within Microsoft Excel but that is where my expertise finishes. Is there a certain calculation or method that should be used to do the following below?
Scenario 1
Enter a number which will convert to time (example 75 converts to 01:15 (HH:MM)).
Then from this field, in a currency field the amount of time displayed is a dollar amount at the rate of $85.00 per hour. So in the case of 01:15 this would be $99.17
Scenario 2
I would presume this would be similar to the one mentioned above, that entering in a single number (eg. 2, or 13) and having a separate field that would calculate 1 unit at $50.
Therefore if '2' was entered it would be $100, and if '13' was entered it would be $650.
If anyone could let me know what I need to do to obtain these calculations or javascript that would be helpful - even if you are able to point me in the right direction of learning javascript and knowing how to perform these calculations myself - perhaps some good books out there?
Thanks for your time, and look forward to reading some replies...
Regards, Shaun (sticks1977)
By the number 75, I assume you mean 75 minutes.
If so, a time calculation is unnecessary, just divide the number by 60 and multiply that by the hourly rate.
However, you are requiring the user to enter the total time in minutes when it would be better to enter the time as hours and minutes (so for 75 it would be 1 hour 15 minutes).
The code below assumes the following fields:
Hours, Minutes, Hour Rate and Total
They should be formatted as numbers only and the Total field should have 2 decimal places.
For the Total field enter a Custom calculation script:
Code:
//Formatted as number, no decimal places
var nHrs = this.getField("Hours");
//Formatted as number, no decimal places
var nMins = this.getField("Minutes");
//Formatted as number, decimal places (2 if you need to set a value like $50.57 for example) and read only
//This to show the user the hourly rate in advance
var hrRate = this.getField("Hour Rate");
//calculate
event.target.value = (nHrs.value + (nMins.value/60)) * hrRate.value;
//optional - this removes zeroes if Hours and Minutes are empty
if (event.target.value == 0) event.target.value = "";
I'm sure you can do the rest from here.