Skip to main content
Participating Frequently
April 15, 2025
Answered

Field not updating correctly after selection change

  • April 15, 2025
  • 2 replies
  • 785 views

I don't like that I have to ask what seem like such simple questions.  Every time I think I understand some of it... doesn't seem to work out.

 

I have an order form with a bunch of tables and total fields.  At the top I have a drop down to select what the PaymentMethod is, and I have 3 read-only text fields for Subtotal, processing fee, and Total.  I got a script to work on the Fee field.  A fee is only applied if Credit Card or PayPal is selected from the PaymentMethod dropdown.  Otherwise do nothing (leave the fee as 0).  The Subtotal field uses the basic sum calculation (selected all the table Total fields and let Acrobat figure out the script).  The Overall Total is set to be a simple sum of the Subtotal and Fee fields (selected the 2 fields and let Acrobat figure out the script).  The problem is the Overall Total doesn't seem to update correctly.  It might work the first time, but then I either change a value in a table row's total or I change the PaymentMethod, and the Overall Total doesn't update properly.  Example: 

  • PaymentMethod = US Check (so should be 0 for the fee), Subtotal = 110, fee shows 0, Total = 110. 
  • If I change the PaymentMethod to PayPal, subtotal = 110, fee = 3.85, total = 110. 
  • If I further change a value and the subtotal updates to $285.00, fee updates to $9.98, and total updated to $288.85.  That's only about $3 more, not the $9.98 more. 

 

Any thoughts on why my Total field isn't updating upon changes occurring?  

Don't know if it is helpful, but here's the script that is on the fee field.

var PayType = this.getField("PaymentMethod").valueAsString;
var Subtotal = this.getField("WOSubtotal").value;

if (PayType == "PayPal" || PayType == "Credit Card") {
	event.value = Subtotal * 0.035 }
else {
	event.value = 0; }

 Thanks in advance! 

Correct answer Bernd Alheit

Change the field calculation order.

2 replies

Thom Parker
Community Expert
April 15, 2025

In "Prepare Form" mode, look on the "More..." menu

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
RedrockCAuthor
Participating Frequently
April 15, 2025

Oh!  Thank you!  I've never seen that listed before.  Wonder how long that has been a feature.  Haha  I knew the fields were in the correct tab order, but never seen that property before.  

 

Thank you! 

Thom Parker
Community Expert
April 15, 2025

Calculation order has been around as long as there have been calculations. Maybe 25 or more years?

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Bernd Alheit
Bernd AlheitCorrect answer
Community Expert
April 15, 2025

Change the field calculation order.

RedrockCAuthor
Participating Frequently
April 15, 2025

Sorry, I'm not sure what you mean? ... 

The order the fields are laid out in the document?  Or the order of lines in the script?  

Thom Parker
Community Expert
April 15, 2025

It is the order in which the fields are calculated.   For example, if the "Sum" field calculates before any one of the "Fee" fields, then the sum will be missing that fee value.  So it's important that all of the fee values are calculated before they summed. 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often