Often, in forms, fields depend on each other. For example, the sales tax may depend on
which state the customer lives in. Shipping charges may depend on the total weight of the
order. The total weight of the order may depend on the number of items ordered. And so
Let’s say you have a 3-line order form and you want to display a subtotal that is the sum
action to the Calculate tab. Your custom calculation code will look something like:
var field1 = this.getField('FirstItem');
var field2 = this.getField('2ndItem');
var field3 = this.getField('3rdItem');
var subtotal = this.getField('Subtotal');
subtotal.value = field1.value + field2.value + field3.value;
familiar to you, you should spend a few moments studying it.
We haven’t written this code in the most elegant manner, by any means. Note that when you
are setting up the Field Properties for your form, you can give your fields names like
Item.1, Item.2, Item.3, etc. That way, if you need to change an appearance attribute
globally, you can do something like:
var items = this.getField('Item');
items.fillColor = color.red;
Editing color pattern
With these two lines of code, you can change the fill color for an unlimited number of
objects with similar names.
Note: The name-overloading trick will not work for setting field values. There,
you have to obtain individual references to the values and set them one by one.
But the point is, if you need to bind field dependencies, it is quite easy to do so in
script to access the values of the fields you are interested in. This is a common situation
in forms of all kinds.