Copy link to clipboard
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
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?
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.
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.
yes, the order is correct.
Can you post the form so we can examine it?
how do i post the form?
You need to use a filesharing site like dropbox or google drive and post a sharable link in the reply.
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;
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;