Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Auto fill text field based on entry to another text field

New Here ,
Aug 26, 2021 Aug 26, 2021

Copy link to clipboard

Copied

I am looking for a script to auto complete a text field when a specific number is imputted into another field, so that user filling out form does not have to reference another document to find the corresponding number, aim is to reduce human error input by making the document do the hard work.

 

i.e. text fields are 'Origination - Unwind Direction 1' (this is field 1) & Origination - Unwind Direction 2' (this is field 2)

 

If I were to enter '1' in to Field 1, I want Field 2 to automatically show '2', or if i were to enter '3' into Field 1, I want Field 2 to show '4'. Input will continue roughly on this basis.

 

Aim is to lock Origination - Unwind Direction 2 (Field 2) from user filling out form so that errors cannot occur, thansk for any help

 

TOPICS
How to, JavaScript, PDF forms

Views

54

Likes

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

Adobe Community Professional , Aug 26, 2021 Aug 26, 2021
From example you posted, you can use script in first field under validation: if(event.value == 1)this.getField("Origination - Unwind Direction 2").value = 2; else if(event.value == 3)this.getField("Origination - Unwind Direction 2").value = 4; from here you can continue adding 'else if' statements and if you wish, statement to empty field 2 if field 1 is empty. In your example field 2 is always 1 more then field 1, if that will be case you can use this script in same place instead of script abov...

Likes

Translate

Translate
Adobe Community Professional ,
Aug 26, 2021 Aug 26, 2021

Copy link to clipboard

Copied

From example you posted, you can use script in first field under validation:
if(event.value == 1)this.getField("Origination - Unwind Direction 2").value = 2;
else if(event.value == 3)this.getField("Origination - Unwind Direction 2").value = 4;

from here you can continue adding 'else if' statements and if you wish, statement to empty field 2 if field 1 is empty.

In your example field 2 is always 1 more then field 1, if that will be case you can use this script in same place instead of script above:
var x = Number(event.value);
this.getField("Origination - Unwind Direction 2").value = event.value != "" ? x+1 : "";

Likes

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 ,
Aug 26, 2021 Aug 26, 2021

Copy link to clipboard

Copied

LATEST

Thanks, worked like a dream

Likes

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
Adobe Employee ,
Aug 26, 2021 Aug 26, 2021

Copy link to clipboard

Copied

Hi Craiga

 

Hope you are doing well and sorry for the trouble. As described you want a script to auto complete a text field when a specific number is imported into another field, so that user filling out form does not have to reference another document to find the corresponding number.

 

For information about developing JavaScript please check the help page https://acrobatusers.com/tutorials/javascript_console/

 

Hope this information will help

 

Regards

Amal

Likes

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