Skip to main content
Participant
July 3, 2023
Answered

Auto-fill text field (allowing for override), based on drop-down field value

  • July 3, 2023
  • 1 reply
  • 1214 views

Dear all,

 

I'm working with Actobat Pro, and have a PDF fillable form with 2 fields, named "Sender" and "Recipient", that contain identical drop-down values (e.g. "Dept 1", "Dept 2", "Dept 3", etc.).  I also have 2 other fillable text fields named "SenderEmail" and "RecipientEmail" for which I have a list of default values (e.g. "Dept1@company.com", "Dept2@company.com", "Dept3@company.com", etc.).

 

I want the "SenderEmail" and "RecipientEmail" fields to auto-fill with the default values, based on the value that is selected in the corresponding "Sender" and "Recipient" drop-down field, but I want the user to be able to override the auto-filled text with a custom value (e.g. "John.Dept1@company.com", "Jane.Dept2@company.com," "Joe.Dept3@company.com", etc.).

 

Anybody have a recommendation on how to accomplish this?  I'm not javascript fluent, but can figure it out pretty well if somebody gives me examples or a tutorial.  (FYI: I tried this guidance -- https://acrobatusers.com/tutorials/change_another_field/ -- but it won't work, I think because the drop-down values in the "Sender" and "Recipient" field are identical.)

Thank you so much!

This topic has been closed for replies.
Correct answer Theresa30857133a0ly

Hey Thom, thanks again.  Unfortunately, I couldn't get your guidance to work for what I was doing.  But it led me to another support article (https://community.adobe.com/t5/acrobat-sdk-discussions/newby-auto-populate-text-field-with-statement-by-selecting-drop-down-menu/m-p/9555104#M27731) which was much simpler and did exactly what I was needing.  I am just running a custom validation script in the drop-down field's "Validate" properties, and autofills the corresponding field and also allows the user to modify the autofilled value.  

1 reply

Thom Parker
Community Expert
Community Expert
July 3, 2023

I think this article and sample file will get you pretty close:

https://acrobatusers.com/tutorials/list_and_combo_in_lc/

 

It's very similar to the other article you've referenced. I suspect the problem you are having with that code is related to the destination field names, which are hard coded in the script.  Since you have two dropdowns and two destination fields you need a way to ensure each dropdown is writing data to the correct destination.  Hard coding the field names only works if you write individual scripts for each dropdown. 

 

For example:

function SetFieldValuesSender(cDeptName) { 
    // Populate fields with values from the Department Data Object 
    this.getField("Sender.DeptContact").value = DeptData[cDeptName].contact; 
    this.getField("Sender.DeptEmail").value = DeptData[cDeptName].email; 
    this.getField("Sender.DeptNumber").value = DeptData[cDeptName].deptnum; 
} 

function SetFieldValuesReciever(cDeptName) { 
    // Populate fields with values from the Department Data Object 
    this.getField("Reciever.DeptContact").value = DeptData[cDeptName].contact; 
    this.getField("Reciever.DeptEmail").value = DeptData[cDeptName].email; 
    this.getField("Reciever.DeptNumber").value = DeptData[cDeptName].deptnum; 
} 

     

  Both functions reference the same data, since both dropdowns have the same entries. But Each function references different target fields. 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
July 3, 2023

Sorry, I don't think that's what I'm needing; and it seems way more complicted that I'm looking for.  I don't want the user to be able to change the drop-down default list values; those have to remain unchanged.  I just want the user to be able to "tweak" the default fault auto-filled value once it has been auto-filled.  Anybody else have ideas?