Copy link to clipboard
Copied
Okay, so I am trying to build a risk assessment calculator. This requires me to add up the boxes riskFactor1a, riskFactor2a, riskFactor3a, riskFactor4a, and riskFactor5a (the a is important because this gets repeated 4 times with different types of risk and those are b, c, and d). However, the slightly more complicated bit is that I need to add these up but not let them exceed 10. If their sum exceeds ten, the textbox should still only display 10. This seems remarkeably simple yet it is proving weirdly frustrating and I cannot get it to work right. If anyone has a good answer for this I would greatly appreciate it, thank you in advance.
Use this:
if(total == 0) event.value = "";
else if (total > 10) event.value = 10;
else event.value = total;
Use what Bernd suggested, just fix mistype ( If to if) and also change:
total+riskFactor
to:
total+=riskFactor
Copy link to clipboard
Copied
If you want to add all the numeric export values assigned to each of these radio buttons with, change the names for each fields using a parent-child naming hierarchy and employe the getArray() method.
For example, instead of naming all of these fields like:
riskFactor1a
riskFactor1b
riskFactor1c
riskFactor1d
Use a prefix like :
risk.Factor1a
risk.Factor1b
risk.Factor1c
But, even easier, you can just create all of them under the same group name "risk", for example, and then assign a different export value to each radio button.
This will make them mutually exclusive, and also it will make it easy to keep your script short and simple with the getArray() method.
Would you mind describing which method are you currently using that is proving to be weirdly frustrating?
If you can, please share the script that you're using.
Copy link to clipboard
Copied
So just to provide some context, I am incredibly new to using javascript especially within acrobat so I have an exceptionally vague notion of what the getArray does, but not a very clear one, and I don't really get the parent child hierarchy. Here is what I am using. It is a modification of what someone else had helped me with to do a similar yet different thing. Clearly my modifying of it broke the thing.
var total = 0;
for ( var i=1; i<=5; i++)
{
var riskFactor = this.getField("probRiskFactor"+i+"a").value;
if(this.getField("probRiskFactor"+i+"a").valueAsString != "Off")
total+riskFactor;
}
if(total == 0)
event.value = "";
else
event.value = riskFactor;
Copy link to clipboard
Copied
Use this:
if(total == 0) event.value = "";
else if (total > 10) event.value = 10;
else event.value = total;
Copy link to clipboard
Copied
Awesome, this worked, thank you so much.
Copy link to clipboard
Copied
Use what Bernd suggested, just fix mistype ( If to if) and also change:
total+riskFactor
to:
total+=riskFactor
Copy link to clipboard
Copied
That worked, thank you for helping me again haha.