Skip to main content
Known Participant
February 20, 2025
Answered

Fill a text field from dtaa in a drop down menu

  • February 20, 2025
  • 4 replies
  • 624 views

I have 3 fields I'd like to fill as text fields based on a drop down menu selection.

 

My dropdown field is "Client Name"

The text fields I'd like to fill based on my drop down choice are:

Text field 1:  Account number

Text Field 2: Purchase Order number

Text Field 3:  Name of client from the drop down menu

 

Thanks in advance to anyone who can help me.

    Correct answer try67

    Put quotes around all the values.

    4 replies

    Nesa Nurani
    Community Expert
    Community Expert
    February 20, 2025

    You can use this script in the dropdown field as a Validate script:

    var cList = {
     "Client Name1": { accountNum: 123, orderNum: 111 },
     "Client Name2": { accountNum: 234, orderNum: 222 },
     "Client Name3": { accountNum: 345, orderNum: 333 }
    };
    
    var f1 = this.getField("Text1");
    var f2 = this.getField("Text2");
    var f3 = this.getField("Text3");
    var selectedName = event.value;
    
    if (cList[selectedName]) {
     f1.value = selectedName;
     f2.value = cList[selectedName].accountNum;
     f3.value = cList[selectedName].orderNum;} 
    else {
     f1.value = "";
     f2.value = "";
     f3.value = "";}
    

    Replace "Text1", "Text2", and "Text3" with the actual field names in your form.

    Replace "Client Name1", "Client Name2", etc., with the names that appear in your dropdown field.

    Update the accountNum and orderNum values with the correct numbers for each client.

    If you add more clients, simply add a new line inside cList, using a comma after each entry (except the last one).

     

    Known Participant
    February 20, 2025

    Ms. Nurani,

     

    Once again, you've proven to be very helpful.  Thank you for this.

     

    Only fly in the ointment is my account numbers are alphanumeric.  Your script works perfectly for numeric entries, but I get a syntax error when attempting to make the account number alphanumeric:

     

    SyntaxError: missing } after property list 2: at line 3 

     

    Example of an account number:  ATPL 12345

     

    Thank you so much for your help.

     

    Sincerely,

     

    Mark

    try67
    Community Expert
    try67Community ExpertCorrect answer
    Community Expert
    February 20, 2025

    Put quotes around all the values.

    try67
    Community Expert
    Community Expert
    February 20, 2025

    As the custom validation event of the drop-down field enter code like this:

     

    if (event.value=="John Smith") {
    	this.getField("Text field 1").value = "12345";
    	this.getField("Text field 2").value = "99999";
    	this.getField("Text field 3").value = event.value;
    } else if (event.value=="Jane Doe") {{
    	this.getField("Text field 1").value = "23456";
    	this.getField("Text field 2").value = "88888";
    	this.getField("Text field 3").value = event.value;
    }
    //etc.
    else {
    	this.getField("Text field 1").value = "";
    	this.getField("Text field 2").value = "";
    	this.getField("Text field 3").value = "";
    }
    
    

    Adjust the field names and values as needed, of course.

    kglad
    Community Expert
    Community Expert
    February 20, 2025

    you have other posts in the acrobat forum, so i'm not sure why you posted in a forum that for discussions about adobe's forums.

     

    in the future, to find the best place to post your message, use the list here, https://community.adobe.com/

    p.s. i don't think the adobe website, and forums in particular, are easy to navigate, so don't spend a lot of time searching that forum list. do your best and we'll move the post (like this one has already been moved) if it helps you get responses.



    <"moved from using the community">
    kglad
    Community Expert
    Community Expert
    February 20, 2025

    which app?  acrobat pro?