Validation script calculation remains a step behind


hello. i'm working on project has rows of 3 text fields values must added , total row in fourth field. goes on many lines. this:

[total.0] = [a.0] + [b.0] + [c.0]

[total.1] = [a.1] + [b.1] + [c.1]

[total.2] = [a.2] + [b.2] + [c.2]

, on.

 

i wanted script calculated appropriate totals when 1 of corresponding values changed, instead of recalculating time.

it suggested me should use validation script, run when value committed text field. know little of javascript, after reading around bit, had set document level script:

 

function calctotals()

{

//i believe gives me number post "." on field name, correspond each row needs added up

var n= event.target.name.split(".").pop();

 

//the next 3 variables supposed give me values of a, b , c corresponding appropriate row

var va = +getfield("a." + n).value;

var vb = +getfield("b." + n).value;

var vc = +getfield("c." + n).value;

 

//then i'd add row

 

var t = va + vb + vc;

 

//and assign corresponding total field

 

getfield("total." + n).value = t;

}

 

after this, tested out, running calctotals(); custom validation script in first a, b , c fields.

 

the issue i'm having that, while total.o become sum of a.0, b.0 , c.0, step behind. so:

starting zero:

a.0 = 0

b.0 = 0

c.0 = 0

total.0 = 0

 

change 1 value , total remains zero

a.0 = 3

b.0 = 0

c.0 = 0

total.0 = 0

 

change second value, , total becomes correct sum:

a.0 = 3

b.0 = 0

c.0 = 2

total.0 = 3

 

a third change give total of result after second change:

a.0 = 3

b.0 = 7

c.0 = 2

total.0 = 5

 

and on. calculation 1 changed value behind. ideas on how fix that, while keeping calculation happening appropriate roll when 1 values changed? preferably document level script can call appropriate, instead of having write individual scripts each roll.

whenever validation looks step behind, have problem calculation order. gets calculated before necessary information available. @ calculation order , make sure things other calculations depend on calculated first.



More discussions in JavaScript


adobe

Comments

Popular posts from this blog

Reader DC

AdobeIDの作り方

Adobe InDesign CC 2017 has stopped working