Skip to main content
Known Participant
July 5, 2020
Answered

How to auto add values from text fields to Combo Box/Dropdown list?

  • July 5, 2020
  • 2 replies
  • 3203 views

On my PDF I have three Email Address text fields - when a value is entered into one of these fields I would like the entered value to automatically be added to a combo box to allow the user to select which email address they would like to use to receive correspondence. 

 

So far I have the following code added to the combo box: 

 

 

var emailList = [" "];

if(this.getField("EmailAddress1").value) {
emailList.push([this.getField("EmailAddress1").value]);
}

if(this.getField("EmailAddress2").value) {
emailList.push([this.getField("EmailAddress2").value]);
}

if(this.getField("EmailAddress3").value) {
emailList.push([this.getField("EmailAddress3").value]);
}

this.getField("PortfolioCorrespondenceEmail1").clearItems();
this.getField("PortfolioCorrespondenceEmail1").setItems(emailList);

 

 

 

 

This code does return the values as hoped, however, I am required to click in the dropdown to refresh the values in the list, this may give the impression to users that there are no emails available for selection as initially there is just a " " option until the values are loaded into the list.

 

I have selected "commit selected value immediately" but it doesn't seem to fix the problem. At the moment I have no code in the custom keystroke, I am wondering whether there is something I should add in there?

 

Update: I have since moved the code into the custom calculation area and the dropdown list options are populating immediately, however it won't let me select one of the options. When I select one of the options it just looks like the list is reloading and the option doesn't select. 

 

This topic has been closed for replies.
Correct answer ls_rbls

Honestly this is all you need:

 

var f = event.target;
var emailList = [event.value,""];

if(this.getField("a").value) {emailList.push([this.getField("a").value]);} 

if(this.getField("b").value) {emailList.push([this.getField("b").value]);} 

if(this.getField("c").value) {emailList.push([this.getField("c").value]);}


f.setItems(emailList);

 

You can run it as custom calculation script and also as custom format script.

 

It updates on real-time and if the user deletes the other two email and decides to delete the third entry, clicking on the empty item of the drop down menu clears the box.

 

 

2 replies

ls_rbls
ls_rblsCorrect answer
Community Expert
July 6, 2020

Honestly this is all you need:

 

var f = event.target;
var emailList = [event.value,""];

if(this.getField("a").value) {emailList.push([this.getField("a").value]);} 

if(this.getField("b").value) {emailList.push([this.getField("b").value]);} 

if(this.getField("c").value) {emailList.push([this.getField("c").value]);}


f.setItems(emailList);

 

You can run it as custom calculation script and also as custom format script.

 

It updates on real-time and if the user deletes the other two email and decides to delete the third entry, clicking on the empty item of the drop down menu clears the box.

 

 

Abbccc96Author
Known Participant
July 7, 2020

Thanks for the help guys. Got it working as hoped now, appreciate the time you spent helping me. 

ls_rbls
Community Expert
July 5, 2020

Drop the ("") quotes inside the brackets.

 

And use code like this: 

 

var f = event.target;
var emailList = [];

if (!event.willCommit) {

if(this.getField("EmailAddress1").value) {emailList.push([this.getField("EmailAddress1").value]);} 

if(this.getField("EmailAddress2").value) {emailList.push([this.getField("EmailAddress2").value]);} 

if(this.getField("EmailAddress3").value) {emailList.push([this.getField("EmailAddress3").value]);}

f.setItems(emailList);

} 

 

Copy the code above and paste it in the Custom Fomat Script section  instead of Custom Key Stroke or custom calulation script.

Abbccc96Author
Known Participant
July 6, 2020

Thanks for the response, I am getting the same problem. When I select the item in the drop down it doesn't stay selected. It just reloads the list and selects the first item in the array as the value. However, it does auto update the value, just need to to sort out the value selection side of it working now so the value persists. Do you have any idea on how to fix this?

ls_rbls
Community Expert
July 6, 2020

Added a space between the brackets at line: 

var emailList = [];

 but the outcome is still the same, unfortunately. It's a strange one this as I do have the code exactly as you provided (now with the updated space) but it's not working for me and is for you.

 

If you have the time, is there a way I can send you this file and you can see if I'm being a numpty somewhere? I believe I have followed the instructions you have given by taking an exact copy and paste of the code and entering it into the Custom Format Script on the drop-down with no code running elsewhere. 

 

Also, did the GIF work for you? (Its clearer if you open it in a new window, it shows how I have set up the code in the dropdown). 


Sure, just click on the "Share" button and it will generate a link that you can copy and share it here in this thread so all the parties trying to help can evaluate it, or if you feel more comfortable send it as a private message (either way is fine).