Copy link to clipboard
Copied
I have the following script... the output calculation displays "Off" for the boxes the are unchecked (see image). The calculation still works in the end; I have a second field referencing the summed hidden field as a hack to get around the "Off" displaying, but have found that browsers can't handle this.
Two days and I can't work this out. I know it would be simple but I'm Just a cut and past coder still... Can someone point out how to checkl the value of a check box and return 2 if checks and "" if unchecked?
var v1 = this.getField("Check Box4").value;
if (v1 /= "") {
event.value = this.getField("Level").value
+ this.getField("Check Box4").value
+ this.getField("Check Box5").value
+ this.getField("Check Box6").value
+ this.getField("Check Box7").value;
}
if (isNaN(v1) || v1 === "") {event.value = "0";}
Copy link to clipboard
Copied
You can use something like this:
var v1 = this.getField("Check Box4").valueAsString=="Off" ? "" : 2;
Copy link to clipboard
Copied
When either a checkbox or a radio button is unchecked, the value is always "Off". So, when checkboxes are being added together for a numerical value, the addition has to be qualified. As Try67 has so generously shown in his post.
However, there are some additional issuew with the code, v1 will never be blank, i.e. "", instead the code needs to test for "Off". Also the "/=" operator is for dividing a value. I think you meant "!=", the inequality operator.
Here's an updated version of the code. I've used 1 as the assumed value of the checkboxes. This will need to be changed to the real value being exported form the checkbox.
var v1 = this.getField("Check Box4").value;
if (v1 != "Off") {
event.value = this.getField("Level").value
+ (this.getField("Check Box4").value=="Off"?0:1)
+ (this.getField("Check Box5").value=="Off"?0:1)
+ (this.getField("Check Box6").value=="Off"?0:1)
+ (this.getField("Check Box7").value=="Off"?0:1);
}
else
{event.value = "0";}
Copy link to clipboard
Copied
I ended up figuring out what seems to be a very ineligant solution, but it works. I will try yours. ty
var v0 = this.getField("Level").value;
var v1 = this.getField("Check Box4").value;
var v2 = this.getField("Check Box5").value;
var v3 = this.getField("Check Box6").value;
var v4 = this.getField("Check Box7").value;
if (v1 != 2) { event.value = "";}
else if(v1 == 2 & v2 == 2 & v3 == 2 & v4 == 2) {event.value = 8 + v0;}
else if(v1 == 2 & v2 == 2 & v3 == 2 & v4 !== 2) {event.value = 6 + v0;}
else if(v1 == 2 & v2 == 2 & v3 !== 2 & v4 !== 2) {event.value = 4 + v0;}
else if(v1 == 2 & v2 !== 2 & v3 !== 2 & v4 !== 2) {event.value = 2 + v0;}
else if(v1 == 2 & v2 !== 2 & v3 == 2 & v4 !== 2) {event.value = "x";}
else if(v1 == 2 & v2 !== 2 & v3 !== 2 & v4 == 2) {event.value = "x";}
else if(v1 == 2 & v2 == 2 & v3 !== 2 & v4 == 2) {event.value = "x";}
else if(v1 == 2 & v2 !== 2 & v3 == 2 & v4 == 2) {event.value = "x";}
Copy link to clipboard
Copied
Yep, that code seems like the very long way around 😉
Copy link to clipboard
Copied
the benefot thou is that it returns 'X' when there is a check box order error as required in my protocol. As in, the series of check boxex should only be checked from lower to highest, any other combination result in "" or "X".
Copy link to clipboard
Copied
That requirment wasn't mentioned in the first post. If there is an ordering issue, then there needs to be an ordering element to the calculation. Best way to do this in a generic way is to use a loop.
var nSum = this.getField("Level").value;
var bTestErr = false; // State variable
for(var i=4;i<8;i++)
{
val = this.getField("Check Box" + i).value=="Off"?0:2;
if(bTestErr && val)
{
nSum = "X";
break;
}
else if(val)
nSum += val;
else // any checks beyond this point are not allowed
bTestErr = true;
}
event.value = nSum;
I did not add in the "if" check for the first checkbox. This is just the straight calculation.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now