Copy link to clipboard
Copied
I have three fields, "OvertimeHrs", "OvertimeAmount" and "TotalPay".
OvertimeHrs is for user input and not calculated
OvertimeAmount is calculated by multiplying OvertimeHrs times a specific number, and is working:
var v1 = this.getField("OvertimeHrs").value;
event.value = 30 * v1;
TotalPay is calculated by adding OvertimeAmount to a specific number, and is also working:
var v2 = this.getField("OvertimeAmount").value;
event.value = 15 + v2;
Now I would like to edit the code, but I don't know the syntax. If the OvertimeHrs field is blank, I would like to have the other two fields to be empty and allow regular user input. So in OvertimeAmount, it would something like:
if OvertimeHrs is not blank, do the calculation, else do nothing (leave box empty, no zero or anything)
And in TotalPay, if OvertimeHrs is not blank, do the calculation, else do not calculate and allow user input.
Is this possible, and if so could anyone tell me what the syntax would be for that? Thank you for your help!
Copy link to clipboard
Copied
Allowing manual entry is a different kind of issue. When a field is calculated the code is forcing a value. So any entry is fighting the built-in behavior. The solution is to add code that blocks the calculation from having an effect.
Here's how it works:
var v1 = this.getField("OvertimeAmount").value;
event.value = 15 + v2;
event.rc = (v1 != ""); // this blocks the calc
event.target.readonly = event.rc // This blocks or enables user data entry
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Yes, it is possible.
All you need to do is to test the value of the input field to the calculation for an empty value.
For example:
var v1 = this.getField("OvertimeHrs").value;
if(v1 == "")
event.value = "";
else
event.value = 30 * v1;
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Thank you, Thom! This works perfectly for the OvertimeAmount field, but for the TotalPay field, Is there a way to tell it to completely ignore any code is the variable tests empty? Right now it's forcing a blank in TotalPay when there's no value in the variable, but I would like it to allow user input in TotalPay when there's nothing in OvertimeHrs. Thank you for your help!
Copy link to clipboard
Copied
Allowing manual entry is a different kind of issue. When a field is calculated the code is forcing a value. So any entry is fighting the built-in behavior. The solution is to add code that blocks the calculation from having an effect.
Here's how it works:
var v1 = this.getField("OvertimeAmount").value;
event.value = 15 + v2;
event.rc = (v1 != ""); // this blocks the calc
event.target.readonly = event.rc // This blocks or enables user data entry
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Thom, thank you so much! That did the trick! I appreciate your help!!!
ps- Both of your answers are correct, but I can only pick one... wish I could pick both!

