Copy link to clipboard
Copied
How do I print the results of var i in a for loop using console.PrintIn();?
I'm writing the for loops to target specific button widgets that are 1 to 9 (this.getField("button." + 1, 3, 5, 7, 9) to hide those specific widgets. I'm trying to figure out why this isn't working by writing a for loop that will return odd numbers using the modulus operator.
I'm getting an error that console.printIn() is not a function. I've tried several variations of the below code...
for(var i = 1; i < 10; i++) {
if((i % 2) != 0) {
console.printIn(i);
}
}
Here's the actual code I'm writing. I'm not getting any JS errors, but the addition of this snippet seems to crash Acrobat everytime whereas it did not before the new for loop was introduced:
for(var i = 1; i < 10; i++) {
if(i % 2 != 0) {
this.getField("enclosure.2." + i).display = display.hidden;
this.getField("enclosure.4." + i).display = display.hidden;
this.getField("enclosure.6." + i).display = display.hidden;
}
}
It's println, not printIn...
PS. An easier way of doing what you're trying to do is to increment the value of i by 2 in each iteration, instead of using the modulo operator...
Copy link to clipboard
Copied
It's println, not printIn...
PS. An easier way of doing what you're trying to do is to increment the value of i by 2 in each iteration, instead of using the modulo operator...
Copy link to clipboard
Copied
I knew it was something easy. Thanks for the tip!
Would incrementing what you're suggesting be something like:
for(var i = 1; i < 10; i+2) {
console.println(i);
}
well that would create an infinite loop, so that wouldn't be correct...
This is more like it. Thanks again!
for(var i = 1; i < 10; i+= 2) {
console.println(i);
}
Copy link to clipboard
Copied
Correct, the latter is the correct version.
Copy link to clipboard
Copied
I'd swear it had always been printIn. I've seen it for years and am sure I've used it before—albeit I don't print very often from the console nor do I spend most of my time with acroForms.
Sans-serif fonts make it difficult to distinguish between an uppercase I and a lowercase l. I've seen it on so many forums over the years. You blew my mind today.
Copy link to clipboard
Copied
Additional question:
Do button widgets change each time you spawn a template? The form I'm developing has a cover page and up to 4 additional pages that will spawn based on user selection.
When I checked widget instances yesterday, they were 1, 3, 5, 7, 9 from the template widgets.
Today, they're 11, 13, 15, 17, 19.
If the spawned page will never allow it to be spawned twice, will it always be 11-19 then? It seems like it's incrementing after the template widget instances.
Copy link to clipboard
Copied
If you're not renaming the fields on the spawned pages the new ones will be added to the existing group.
Copy link to clipboard
Copied
I'm not renaming. bRename is false.
While I was working on the script I had spawned pages at some point then applied the new script and the widgets were not working hiding. I went into Organize Pages and saw none of my templates were checked on, so that confirmed they were spawned. Those had 11-19.
I then deleted the spawned pages, clicked on the button to run my script, and then respawned my pages and the widgets were hidden correctly.
Copy link to clipboard
Copied
Sorry, I don't quite follow. When you spawn a page the fields on it should retain their visibility, though.