Javascript, Dropdown lists, and autofill fields
Hi!
Thank you so much to everyone for being here with answers to my many questions! I have a new one.
I’m using Adobe Acrobat Standard on Windows 10. 😊
I have a PDF with the following fields:
Dropdown5 (dropdown list)
FIELD06 (number, no decimals)
FIELD07 (number, no decimals)
FIELD08 (number, two decimals)
FIELD09 (number, two decimals)
1. I need “FIELD06” to autofill with a number based on the selection made in “Dropdown5”.
The properties for “Dropdown5” are set as follows:
Options Tab:
Technician/Mechanic
Engineer
Programmer
Travel
Commit selected value immediately (checked)
Actions Tab:
Select Trigger: On Blur
Select Action: Run a Javascript
The javascript entered after clicking “Add” is:
var selection = this.getField("Dropdown5").value;
var FIELD06 = this.getField("FIELD06");
switch (selection) {
case "Technician/Mechanic":
FIELD06.value = "138.50";
break;
case "Engineer":
case "Programmer":
FIELD06.value = "250.00";
break;
case "Travel":
FIELD06.value = "110.00";
break;
default:
FIELD06.value = "";
}
Format: None
2. I then need “FIELD07” to multiply with “FIELD08” and then the result of that to multiply with “FIELD06” and then for that result to autofill into “FIELD09”.
The properties for “FIELD06” are set as follows:
Format: Number
Decimals: 2
The properties for “FIELD07” and “FIELD08” are set as follows:
Format: Number
Decimals: 0
The properties for “FIELD09” are set as follows:
Format: Number
Decimals: 2
The Custom Calculation Script is:
var FIELD07 = this.getField("FIELD07").value;
var FIELD08 = this.getField("FIELD08").value;
var FIELD06 = this.getField("FIELD06").value;
var FIELD09 = this.getField("FIELD09");
// Ensure values are treated as numbers
FIELD07 = parseFloat(FIELD07) || 0;
FIELD08 = parseFloat(FIELD08) || 0;
FIELD06 = parseFloat(FIELD06) || 0;
// Perform the calculation
FIELD09.value = (FIELD07 * FIELD08) * FIELD06;
3. When a selection in “Dropdown5” is changed, I need:
A) “FIELD06” to instantly update whenever the selection in “Dropdown5” is changed
which would then
B) automatically update the calculation result in “FIELD09”
My trouble:
When I initially select an option from “Dropdown5”, “FIELD06” does not autofill with any amount, it remains blank until I tab or click to the next field, at which point the correct amount then autofills into “FIELD06”.
- and -
When I change the selection in the “Dropdown5” field, “FIELD06” does not instantly update to the correct amount – it waits until I tab or click to the next field.
My questions:
What do I need to do to ensure that “FIELD06” automatically fills with the correct amount when a selection is made in “Dropdown5”, rather than waiting until the user tabs or clicks to the next field? Is it possible?
Thank you so much!
