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

Autofill a form's field using an if condition

New Here ,
Nov 18, 2024 Nov 18, 2024

Copy link to clipboard

Copied

I am attempting to set up a script to run that will automatically complete different types of forms with demographic information- so not all forms that will use the script will be the same. I don't need this to be perfect but would like for when a field says either Zip or Zip Code, either would fill with the correct number because the word Zip appears. I'm using a custom script below that works if the field requested is Zip Code:

 

var zipcodefield = this.getField("Zip Code");

zipcodefield.value = "60690";

 

I am not sure if there is an if condition for that, and if so, I'm not sure how exactly to set it up. Can anyone help?

TOPICS
Acrobat SDK and JavaScript

Views

67

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 , Nov 19, 2024 Nov 19, 2024

Sounds like this should be a folder level automation script that is run from a tool button.

https://www.pdfscripting.com/public/Automating-Acrobat.cfm

 

One way to do this is to search all the fields for ones that match a pattern

 

Here is a brute force approach:

var strFldName;
for(var i=0;i<this.numFields;i++){
   strFldName = this.getNthFieldName(i);
   
   if(/Zip/i.test(strFldName))
       this.getField(strFldName).value = "9999999";
   else if(/State/i.test(strFldName)) 
       this.getFie
...

Votes

Translate

Translate
Community Expert ,
Nov 19, 2024 Nov 19, 2024

Copy link to clipboard

Copied

So if another field's value is "Zip" or "Zip Code" then you want to fill this field with that number? Should the user be able to override this value and change it to something else?

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
New Here ,
Nov 19, 2024 Nov 19, 2024

Copy link to clipboard

Copied

for what I need this, not likely. Ideally it would fill with 60690 for any form that calls for a Zip or Zip Code. Will also be using to fill fields that say "state/province" for example - I want anything that asks for a State to be Illinois

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 ,
Nov 19, 2024 Nov 19, 2024

Copy link to clipboard

Copied

Sounds like this should be a folder level automation script that is run from a tool button.

https://www.pdfscripting.com/public/Automating-Acrobat.cfm

 

One way to do this is to search all the fields for ones that match a pattern

 

Here is a brute force approach:

var strFldName;
for(var i=0;i<this.numFields;i++){
   strFldName = this.getNthFieldName(i);
   
   if(/Zip/i.test(strFldName))
       this.getField(strFldName).value = "9999999";
   else if(/State/i.test(strFldName)) 
       this.getField(strFldName).value = "Illinois";
}

 The regular expressions and the "if" statements can be modified to include more and different conditions. 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
New Here ,
Nov 19, 2024 Nov 19, 2024

Copy link to clipboard

Copied

LATEST

This is it! Much appreciated and hopefully saving our teams a lot of time. Thank you!!

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