Copy link to clipboard
Copied
What is the Java script that is needed for box4 to reflect the count of the number of x's in the form fields box1, box2, box3 disregarding any the blank form fields? In this sample, the form fields are labeled box1, box2, box3, and box4 left to right.
I have found the java script below but do not know where to substitute box1, box2, box3, and box4 or what will need to removed from this java script.
var total = "";
for (var i=1; i<=28; i++) {var f = Number(this.getField("Rating"+i).valueAsString);
if (f > 0 && f <= 4) total++;} event.value = total;
Thank you for your assistance!!
Janelle
Copy link to clipboard
Copied
Would it be correct to use
var total = 0; for(var i=5; i<=7; i++) { var f = this.getField("box"+i).valueAsString; if(f === "X") total++;} event.value = (total == 0) ? "" : total;
Copy link to clipboard
Copied
If the value is exactly "X" use this:
var total = 0;
for(var i=1; i<=4; i++) {
var f = this.getField("box"+i).valueAsString;
if(f === "X") total++;}
event.value = (total == 0) ? "" : total;
Copy link to clipboard
Copied
Thank you! This script works well for a single row. Apparently, I have a lot to learn about Java script.
What would I do if I have a second row of boxes labeled box5, box6, box7 and box8 that require their own calculation of X to be shown in box8? Would I place two different Java scripts in box4 and box8's properties?
Copy link to clipboard
Copied
Would it be correct to use
var total = 0; for(var i=5; i<=7; i++) { var f = this.getField("box"+i).valueAsString; if(f === "X") total++;} event.value = (total == 0) ? "" : total;
Copy link to clipboard
Copied
Yes, use another script for box 8, if you wish to show count in box 4 from (box1,box2 and box3) change 4 to 3 in the loop:
for(var i=1; i<=3; i++) {
For box8 set loop like this:
for(var i=5; i<=7; i++) {
Everything else is the same.
Copy link to clipboard
Copied
Thank you!!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now