Skip to main content
Participant
August 26, 2021
Answered

Auto fill text field based on entry to another text field

  • August 26, 2021
  • 2 replies
  • 3182 views

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

 

This topic has been closed for replies.
Correct answer Nesa Nurani

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 : "";

2 replies

Amal.
Legend
August 26, 2021

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

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
August 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 above:
var x = Number(event.value);
this.getField("Origination - Unwind Direction 2").value = event.value != "" ? x+1 : "";

Participant
August 26, 2021

Thanks, worked like a dream