Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Print For Loop Results using Modulus Operator in Console

Engaged ,
Jun 16, 2021 Jun 16, 2021

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;
	}
}

 

TOPICS
Create PDFs , JavaScript , PDF forms
2.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Jun 16, 2021 Jun 16, 2021

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...

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 16, 2021 Jun 16, 2021

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...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 16, 2021 Jun 16, 2021

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);
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 16, 2021 Jun 16, 2021

Correct, the latter is the correct version.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 16, 2021 Jun 16, 2021

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 16, 2021 Jun 16, 2021

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 16, 2021 Jun 16, 2021

If you're not renaming the fields on the spawned pages the new ones will be added to the existing group.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 16, 2021 Jun 16, 2021

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 16, 2021 Jun 16, 2021
LATEST

Sorry, I don't quite follow. When you spawn a page the fields on it should retain their visibility, though.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines