Skip to main content
Participating Frequently
November 4, 2022
Answered

Populate dropdown field options from other form fields in document

  • November 4, 2022
  • 2 replies
  • 10363 views

Hi, I've scoured other threads but couldn't quite see the answer for what I'm looking for! Hoping someone can help. Apologies if this has been discussed before.

I'm creating a dropdown field where I want x2 dropdown options to be populated from x2 text fields within the document. I can only see the option to manually enter options to display rather than call on other fields to populate these options — can this be done?  Ideally I'd like to name these as Option 1/Option 2 from the dropdown selection but it's okay if these appear as what's written in the text boxes.

I'm assuming some sort of script may be needed to implement? Any help would be greatly appreciated!

I've attached a screengrab of what I'm hoping to achieve if that's useful for guidance.


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

Sorry, under the Format tab there's 2 fields to choose from where to post the JS "Custom Format Script" or "Custom Keystroke Script". I've tried it in both of these fields.

I've popped the fields in a new doc (identical to how they're labelled in my file – I can't post this due to confidentially). Sorry it's probably a really simple thing but due to my lack of knowledge I'm missing the obvious 😅 Thank you in advance.



I think you want something else, please test this file and see if that's what you need:

https://drive.google.com/file/d/1nWuCg1Fg6ZM45K1K6EPshZK56HVWF-cc/view?usp=share_link 

2 replies

ls_rbls
Community Expert
November 4, 2022

Hi beth,

 

++Adding to Karl's always valuable guidance,

 

I just posted an example for another user 10 hours ago, which illustrates an simple example employing the method suggested by Karl.

 

If you're new to Acrobat JavaScript, the API Reference is an excellent choice to get famimiliarized with many methods.

 

Be advised, that I am still learning Acrobat JavaScript, but in the link below is the example script, which you may use and adapt to your workflow:

 

Beth.191Author
Participating Frequently
November 7, 2022

Thank you ls_rbls for your reply. Sadly that doesn't seem to have worked for me (I'm not a JS person at all so I know I've probably gone wrong somewhere! But don't know where!)

My Dropdown box is called Season Dropdown, and the x2 dropdowns under the options tab are labelled as Option 1 and Option 2

The first field is labelled Date 1 which I want to appear as Option 1 in the Season Dropdown and the second field is labelled Date 2 which I want to pull through as Option 2

It won't let me enter this, I'm missing something but I'm not sure if the forumla is even right!? Thanking you in advance!

Beth.191Author
Participating Frequently
November 7, 2022

Apologies, it wouldn't let me post the code becuase of the errors, hence the image! But I don't know where those errors are 😅


I just get this message and it removed bits from the code so I thought an image would be helpful.

Karl Heinz  Kremer
Community Expert
November 4, 2022

You can configure dropdown controls via JavaScript. You could write a script that monitors the form for changes in the relevant fields and then sets new options for the dropdown control. The Field.setItems() function will do that for you: https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/JS_API_AcroJS.html#setitems

Beth.191Author
Participating Frequently
November 7, 2022

Thank you Karl for your reply. I'm still having trouble with this, I know close to nothing about JS so I know I'm doing something wrong!

I've used the below but this isn't pulling the fields, it's just taking the name of the fields than the content of them. Can you advise? Thanking you in advance!

var l = this.getField("Season Dropdown"); l.setItems(["Date 1", "Date 2"]);

My Dropdown box is called Season Dropdown, and the x2 dropdowns under the options tab are labelled as Option 1 and Option 2

The first field is labelled Date 1 which I want to appear as Option 1 in the Season Dropdown and the second field is labelled Date 2 which I want to pull through as Option 2