Copy link to clipboard
Copied
I have a form with 21 rows and corresponding field names that range from 1-21. I would like to create a summary box on the final page of the document that checks the dropdown field titled "Status" and if the status is set to "Secured," to add the text in "FundingOpp" to the list (with a comma to separate entries). I set up a loop with my best guess of the coding to do this, but I am getting a syntax error in the code so I can't even test it. So I need help a) determining where the syntax error is and b) if the code as written (plus the edit for the error) will actually do what I'm guessing it will.
var maxFields = 21;
for (var i=1; i<=maxFields; i++) {
var AcceptedStatus = this.getField("Status"+i).valueAsString;
if (AcceptedStatus=="Submitted" || AcceptedStatus=="Denied" || AcceptedStatus=="Revisit at a Later Date") continue;
var s=this.getField("FundingOpp"+i).value + ", " +;}
event.value = s;
Error reads
"SyntaxError: syntax error
8: at line 9"
Thank you very much for any help you can provide!
The syntax error is there:
var s=this.getField("FundingOpp"+i).value + ", " +;
a) See above.
b) No, because you're overwriting the value of the "s" variable in each iteration of the loop. You need to define this variable before the loop and then add to its current value within in, like this:
var maxFields = 21;
var s = "";
for (var i=1; i<=maxFields; i++) {
var AcceptedStatus = this.getField("Status"+i).valueAsString;
if (AcceptedStatus=="Submitted" || AcceptedStatus=="Denied" || AcceptedStatus=="Revisit at a Later Date") continue;
if (s!="") s+=", ";
s+=this.getFiel
...
Copy link to clipboard
Copied
The syntax error is there:
var s=this.getField("FundingOpp"+i).value + ", " +;
Copy link to clipboard
Copied
a) See above.
b) No, because you're overwriting the value of the "s" variable in each iteration of the loop. You need to define this variable before the loop and then add to its current value within in, like this:
var maxFields = 21;
var s = "";
for (var i=1; i<=maxFields; i++) {
var AcceptedStatus = this.getField("Status"+i).valueAsString;
if (AcceptedStatus=="Submitted" || AcceptedStatus=="Denied" || AcceptedStatus=="Revisit at a Later Date") continue;
if (s!="") s+=", ";
s+=this.getField("FundingOpp"+i).valueAsString;
}
event.value = s;
I also changed it a bit so you don't end up with a loose comma at the end of the list...
Copy link to clipboard
Copied
Brilliant, works beautifully! Also, adding the comma as long as the value is not empty before adding the additional fields is so smart, definitely squirreling that info away! And love the example of establishing variable S outside of the loop to avoid it being rewritten but instead added to. Elegant solution that I learned a lot from!