Copy link to clipboard
Copied
I have a simple subtraction calculation (A-B=C) that worked fine until I designated these fields as either shown/hidden based on the response to a radio button. If radio button 1 is clicked, the fields for A, B, and C are "shown". If any of the other radio buttons (button 2 or button 3) are clicked, A, B, and C are hidden. Once I added this script, the C field no longer calculates. Can anyone help?
Copy link to clipboard
Copied
There's no reason for the visibility of the fields to affect the calculation, so there is something else going on. Have you ensured the calculation (script) is still there? Are A and B calculated values, or are they user entered? Has anything else changed on the form?
Copy link to clipboard
Copied
A is user-entered, b is calculated based on the answer to A. I grouped the 3 fields with the same prefix "T1." so that when the first radio button is selected, these fields are shown. the calculation for B works.
Copy link to clipboard
Copied
Check the field calculation order. Make sure that C is calculated after B. The visibility of the fields has nothing to do with it, as mentioned.
Copy link to clipboard
Copied
yes, the order is correct.
Copy link to clipboard
Copied
Can you post the form so we can examine it?
Copy link to clipboard
Copied
how do i post the form?
Copy link to clipboard
Copied
You need to use a filesharing site like dropbox or google drive and post a sharable link in the reply.
Copy link to clipboard
Copied
thanks. here is the link:
Copy link to clipboard
Copied
There are some problems with one or more of your scripts. Open the Acrobat JavaScript console and you will see the error messages.
You have some field names used in the "Simplified Field Name Notation" calculation that have special characters in their names. These characters cannot be present unless preceded by the JavaScript Escape Character, "\", that indicates the special character is to be treated as a character and not a separator or other special processing character.
Copy link to clipboard
Copied
thank you all, that did it. i didn't know about the JavaScript Escape Character.
Copy link to clipboard
Copied
Another comment is that you are missing code to reset the value of the field in some calculations. For example, under "T1.HrsWk" you have this calculation script:
var a = this.getField("DAF_Score").value;
var b = this.getField("MAF").value;
var c = this.getField("Total_Eligible_HrsWk").value;
var d = this.getField("Tiers").value;
if(a>=25.25 && a<=45 && b=="Yes" && d=="Tier1") event.value = c;
else if (a>=25.25 && a<=45 && b=="No") event.value = "40";
But what if neither one of those conditions are met? In that case the field's value will remain unchanged because you're not applying any value to it. You should probably reset it to a blank string or even zero, by adding this to the end of your code:
else event.value = 0;
Or:
else event.value = "";
Also, I would recommend using valueAsString instead of value, and explicitly converting the values to numbers, where needed, like this:
var a = Number(this.getField("DAF_Score").valueAsString);
var b = Number(this.getField("MAF").valueAsString);
var c = this.getField("Total_Eligible_HrsWk").valueAsString;
var d = this.getField("Tiers").valueAsString;