Copy link to clipboard
Copied
I have seven fields ST1+ST2+ST3+ST4+ST5+ST6+ST7 and the eighth field totalST calculates the total of the ST fields. What I'm trying to figure out is, if the total is over 40 in totalST field then allow the other fields to populate the balance of the total.
Example: If totalST = 45 then 5 would populate into OT1, if totalST is 40 then OT1 would show 0 and so on. Can this be done? With javascript? Can someone provide an example of one I can try? Thanks folks.
Copy link to clipboard
Copied
I think I know what you're trying to do.
The way I would tackle this is by first creating a Document Level function
Tools>JavaScript>Document JavaScripts (You can call it whatever you like)
In this function you will calculate all the required parts.
Here is what the function will look like;
function calcSTFields() {
var ST1 = this.getField("ST1").value;
var ST2 = this.getField("ST2").value;
//Repeat for each ST field
var ST7 = this.getField("ST7").value;
var totalST = this.getField("totalST");
var OT1 = this.getField("OT1");
totalST.value = ST1*1 + ST2*1 + ST3*1 + ... + ST7*1; /*adds all the ST fields together the "*1" is
so if a field is empty it will still add them together rather than concatenate them as 0 x 1 = 0*/
if (totalST.value >= 40) { //if the totalST field is greater than or equal to 40
OT1.value = totalST.value - 40; //OT1's value is equal to totalST minus 40
}
else { //if totalST is not greater than or equal to 40
//do something else
}
}
This should calculate all the ST fields and set values accordingly.
The final step is to call this function in all of your ST fields, or "ST7" if the user must fill in all fields accordingly.
(You can check for empty fields if you want but that's a whole extra approach)
Now to call the function;
In your ST field's Properties>Actions Tab;
On Blur>Run A JavaScript;
calcSTFields();
From there you should be all good.
Hope this helps!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now