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.
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:
Use a prefix like :
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.
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")
if(total == 0)
event.value = "";
event.value = riskFactor;
if(total == 0) event.value = "";
else if (total > 10) event.value = 10;
else event.value = total;
Awesome, this worked, thank you so much.
Use what Bernd suggested, just fix mistype ( If to if) and also change:
That worked, thank you for helping me again haha.