Conditional field values based on dropdown selection
- May 9, 2025
- 2 replies
- 597 views
Hi there
Relatively new to ADOBE forms and scripting.
I have an expense form that has 14 rows and each row has a uniquely identified dropdown (Category) with 6 different values: KM, Accommodations, Meals, Transportation, Other and empty value (" ").
Each dropdown name is obviously different: Cat1, Cat2,..., Cat14. The dropdown is set to Commit Selected Value Immediatelly.
I also have three other fields: Units (u1, u2,..., u14), Cost (c1, c2,..., c14) and Total Value (tv1,..., tv14). The Total Value = Unit*Cost (u1*c1,..., u14*c14).
The idea is that when I select KM, it should automatically set the Cost value to the value I defined (e.g. 0.40) and the Unit ("u1", etc) field is cleared.
When the selection changes to any other option other than KM, the Unit value (e.g. u1) changes to 1 and the cost gets cleared.
I am using the following calculation script for Cat1 dropdown:
if (event.value == "KM") {
this.getField("c1").value = this.getField("MileageCost").value; //MileageCost is another field that has a default value
this.getField("u1").value = "";
}
if (event.value !== "KM") {
this.getField("c1").value = "";
this.getField("u1").value = "1";
}
if (event.value == " ") {
this.getField("c1").value = "";
this.getField("u1").value = "";
}
For the second dropdown Cat2, I am using this calculation script
if (event.value == "KM") {
this.getField("c2").value = this.getField("MileageCost").value; //MileageCost is another field that has the a default value
this.getField("u2").value = "";
}
if (event.value !== "KM") {
this.getField("c2").value = "";
this.getField("u2").value = "1";
}
if (event.value == " ") {
this.getField("c2").value = "";
this.getField("u2").value = "";
}
All other dropdowns use a similar code, with the updated field names for the Unit and Cost
Let's say I am selecting KM in th efirst dropdown for Cat1. The u1 clears and c1 becomes 0.40. Then I enter the u1 value, let's say 100. The tv1 shows $40.00. All good so far
Then for Cat2 dropdown I select Meals.
The u2 populates the "1" and c2 field clears. I now enter a cost in the c2 field. Let's say 50.
This is the part I cannot figure it out yet... Once the cost value for c2 is entered, the Unit value of u1 gets erased. Similarly, if I enter 100 in the Units for u1, the Cost value of c2 gets erased.
I am not sure if this is triggered by the fact that all 14 dropdowns use the same values: KM, Meals, etc.
I thought the fact that each dropdown is uniquely identified will alow me to reach the results I wanted.
