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

Print For Loop Results using Modulus Operator in Console

Engaged ,
Jun 16, 2021 Jun 16, 2021

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

 

TOPICS
Create PDFs , JavaScript , PDF forms

Views

1.4K

Translate

Translate

Report

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

correct answers 1 Correct answer

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

Votes

Translate

Translate
Community Expert ,
Jun 16, 2021 Jun 16, 2021

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

Votes

Translate

Translate

Report

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

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Correct, the latter is the correct version.

Votes

Translate

Translate

Report

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

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.

Votes

Translate

Translate

Report

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

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.

Votes

Translate

Translate

Report

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

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.

Votes

Translate

Translate

Report

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

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

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