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

Searching all fields [Javascript]

Participant ,
Apr 29, 2021 Apr 29, 2021

Im trying to make a form where if I hit a button all fields containing the word: "General" will be. changed to ""(nothing). 

Is this possible?

TOPICS
Create PDFs , Edit and convert PDFs , How to , JavaScript , PDF forms
3.1K
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 ,
Apr 30, 2021 Apr 30, 2021

Assuming these are text fields, you can do it using this code:

 

for (var i=0; i<this.numFields; i++) {
	var f = this.getField(this.getNthFieldName(i));
	if (f==null) continue;
	if (f.type=="text" && /General/.test(f.valueAsString)==true) {
		f.value = "";
	}
}

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
Adobe Employee ,
Apr 29, 2021 Apr 29, 2021

Hi Flynn

 

Hope you are doing well and sorry for the trouble. As described, you want to make a form where if you hit a button all fields containing the word: "General" will be. changed to ""(nothing).

The workflow that you are trying to achieve is possible using the JavaScript. For more details pleae check the help page - https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/js_developer_guide.pdf

 

Regards

Amal

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
Participant ,
Apr 29, 2021 Apr 29, 2021

@Amal. 
Thank you for sending this link over! I do love this book, it is the Koran for adobe acrobat. I have read "Chapter:11 Search and Index Essentials." but it did not seem to mention searching of fields and how to identify the name of the field searched.

Thank you for your reply!

-Flynn

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
Enthusiast ,
Apr 30, 2021 Apr 30, 2021

You want to do it in all fields in file or just specific fields?

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 ,
Apr 30, 2021 Apr 30, 2021

Assuming these are text fields, you can do it using this code:

 

for (var i=0; i<this.numFields; i++) {
	var f = this.getField(this.getNthFieldName(i));
	if (f==null) continue;
	if (f.type=="text" && /General/.test(f.valueAsString)==true) {
		f.value = "";
	}
}
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
Participant ,
May 03, 2021 May 03, 2021

@try67 

They are Dropdown fields.

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 ,
May 04, 2021 May 04, 2021

So change this part of the code:

f.type=="text"

To:

f.type=="combobox"

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
Participant ,
May 04, 2021 May 04, 2021

@try67 

Thank you! 
where do you get this information from?

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 ,
May 04, 2021 May 04, 2021
LATEST

The JavaScript for Acrobat API Reference document, which is a part of the Acrobat SDK: https://opensource.adobe.com/dc-acrobat-sdk-docs/acrobatsdk/

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 ,
Apr 30, 2021 Apr 30, 2021

Hi,

 

To clarify the workflow:

 

  1. User presses button
  2. You search every form field for the fields that contain "General"
  3. If you find any, all the field you finds will have the entire contents set to ""

 

Is that correct?

 

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 ,
Apr 30, 2021 Apr 30, 2021

"Is that correct?"

Yes


Acrobate du PDF, InDesigner et Photoshopographe
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