These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

How to Synchronize Button.value updates across different text fields

mceniry
Registered: Oct 24 2011
Posts: 5
Answered

Hi I've got 11 radio buttons that get summed by the standard "Value is the sum(+)" in one text field (Subtotal) that I'm trying to use in another text field (Total) to set some text based on the total of the buttons. There seems to be a delay in the values being propagated from Subtotal doing the totalling and the text field(Total) evaluating totals. Like when the button total text field(Subtotal) updates, the other text box that should also "see" the updated value does not until another button is clicked on and then the Total "sees" the previous value and not the updated. Is there a way to synchronize these.
 
Here's the code from the 2nd text field (Total):
var mySubt = getField("Subtotal").value;
var myTotalTxt = getField("Total");
 
if (mySubt <= 0)
{ myTotalTxt.value=" ";
}
else
{ event.value= getField("Subtotal").value;
}
 
When field Subtotal gets updated Total reflects the previous
Subtotal value. Click another Button and Subtotal gets updated
correctly but again Total sees previous value that was in Subtotal.
 
What's the trick to fix this?
 
Thanks!!

My Product Information:
Acrobat Pro 6.0, Windows
Merlin
Acrobat 9ExpertTeam
Registered: Mar 1 2006
Posts: 766
Hi,

change the same of the field "Total" into "Subtotal" (same as the 1st field) : their value will be shared immediately.

;-)
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
Accepted Answer
The code for what you describe should be:

  1. // Custom calculate script for Total field
  2.  
  3. // Get the subtotal value
  4. var mySubt = getField("Subtotal").value;
  5.  
  6. // Set this field's value
  7. // based on the subtotal field value
  8. if (mySubt <= 0) {
  9. event.value = " ";
  10. } else {
  11. event.value= mySubt;
  12. }
Also, check to make sure that the field calculation order (which is not the same as the tab order) is correct.
mceniry
Registered: Oct 24 2011
Posts: 5
If I change the Text field names to be the same I lose my code in what was Text Field Total.
If I change my code as per above, Total and SubTotal are still out of synch. I guess the best
solution would be to do the button addition and subtotal evaluations as a script in the same
Text field. Problem is I haven't had much success (none) in adding up my buttons :-).
Any code samples on scripted button value addition?
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
If they are out of sync, this is a good indication that the field calculation order is incorrect. Have you checked it?
mceniry
Registered: Oct 24 2011
Posts: 5
yes, I have Total as the 1st in the list
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
If you can post the form somewhere or email it to me (acroscript at gmail dot com) I'd be happy to take a look.
mceniry
Registered: Oct 24 2011
Posts: 5
it be on its way. Thanks for your help!!