How to delete contents of a form field when it becomes hidden
I've got a basic table in my pdf that looks like this:
| Selection | Category | Amount |
|---|---|---|
| <Category 1 check box> | Category 1 | <Category 1 amount> |
| <Category 2 check box> | Category 2 | <Category 2 amount> |
| <Category 3 check box> | Category 3 | <Category 3 amount> |
| Total | <calculated form field (sum of above)> |
I've used a basic Mouse up javascript on each of the check boxes so that the user can't enter an amount unless they've checked the appropriate box (see below):
// Determine if Check box is marked then use value to show or hide appropriate field
var nHide = event.target.isBoxChecked(0)?display.visible:display.hidden;
// Get the appropriate field and set to show/hide value
this.getField("Category 1 amount").display = nHide;
This set up works great, but has one problem. If someone selects a check box and then puts an amount in, and then later unchecks that box, the total still sums up the value even though it's hidden.
So for example, the user clicks the category 1 check box and then types $10 in the Category 1 amount box. Then they do the same thing for Category 3. The total now reads $20. Great! Except the user now realizes they meant to click category 2 instead of category 3. So they uncheck category 3, click category 2, and enter $10 in category 2. Now the total reads $30 because it's summing the value of all the boxes, even the hidden ones.
My question is this. Is it possible to modify or make a new script that clears the values in the Amount column if the corresponding Selection column check box is unchecked?
