These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Text field data import to Combo Box

DannyBoy
Registered: May 15 2011
Posts: 8

I have looked and looked and I can’t find an answer to this. I have found one combo box affecting another but not my situation. So this is my problem. I have multiple text fields. So let’s call them “Text1, Text2, Text3, Text4, Text5, Text6”. I have a ComboBox1. I want the data that appears in the Text fields to show up in the ComboBox as a list that then can be picked. I have found info on export, but can I import. I want the data in the Text fields to be my items in my Combo Box. As a plus to me, if some Text fields are empty then no empty data shows up in the Combo box as a choice. Is there a JavaScript that can do this?
 
I'm using Acrobat 9 Pro.
Thank you.

My Product Information:
Acrobat Pro 9.4.3, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
To programmatically set the item in a combo box, you'd use the field.setItems method as documented here: http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.752.php

Your script would get the values of the text fields, place them into an array, which can then be use with setItems to populate the combo box.
DannyBoy
Registered: May 15 2011
Posts: 8
Thank you for the site. But what am I doing wrong? This is my script.

var c = this.getField("ComboBox1");
c.setItems(["Text1', "Text2,"]);

So I did it this way

var c = this.getField("ComboBox1");
c.setItems([this.getField("Text1").value, this.getField("Text2").value,])

I get a blank box or a null when ever I switch things. I know I might be writing this wrong. any help you can give me?
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
The problem with the first script is you used two different type of quote characters around Text1. You also placed a comma within the Text2 quotes, but that's wouldn't prevent it from working.

For the second script, remove the final comma that you have, and get the field values using the valueAsString property instead of the value property.




DannyBoy
Registered: May 15 2011
Posts: 8
Thank you,
I think that should work. For those of you that visually need to see the script I wrote, this is was I wrote with the name of the field changed. I put an extra “” for a blank field.

var c = this.getField("ComboBox");
c.setItems(["", this.getField("TextField1").valueAsString, this.getField("TextField2").valueAsString, this.getField("TextField3").valueAsString, this.getField("TextField4").valueAsString, this.getField("TextField5").valueAsString, this.getField("TextField6").valueAsString, this.getField("TextField7").valueAsString]);


However, something is bugging me. If you put this script in the Custom Calculation area I can not select a choice. It auto resets it selves. But when you put the script under “Actions” Mouse Down (is what I used) it works. But what’s bugging me is that when you click on the ComboBox it runs the script over again when it already has the info. I was thinking of attaching the script to a field that I can use the Action On Blur, but I can’t guarantee that I will always use that field so it will update the ComboBox. Just something that is bugging me now that I’m trying to find a work around. It just runs that JavaScript and slows the form down a everytime for me.
But Thank You Again.
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
You should not use this type of script attached to any of the events of the combo box in question. If you provide more details about how the form is being used, particularly how the text field that the combo box items are coming from are used, we may be able to suggest a better approach. You will want to add code to check fi any of the text fields are empty before adding the value to the array, if that will be a possibility.
DannyBoy
Registered: May 15 2011
Posts: 8
Ok. Just to mention I have learned a lot about scripts but I’m still a beginner. I have a set of 7 rows going from pg 1 - 2 for client info to be typed in, “FirstName_1”, ‘MI_1”, and “LastName_1”, plus other info like DOB, Gender, etc. The ones you will see will have them numbered from 1-7. I then created a hidden field named “Named_1Mereged” and I combined both, First & Last Name, to one. The reason for this was because in the first few pages it has clients name split and then at the end the form it wants the name together. So I created a hidden field to get this info, plus to use them for the combo box.So the split names are on page 1 & 2. On pg 3 I have to put in more info on them. Pg 3 is set up like a table, with a lot of rows. Their names have to go there again but this time combined. And I have to choose the individual to go with a certain row, which I have to then put in more info to the right of it, like income, and some other stuff. It is kind a in a table set up. That is why I used a Combo Box. So I can choose the individual I put in pages 1 & 2 to then be used in Pg 3.But like I said before, the combo box is a little slow. And even when I type the individuals name in the first pg it’s slow also because it is sending the info to my “Name_1Mereged” field.

So here is my flow of info. “Name_1Mereged” has a script under custom calculation, and like I said I have 7 of those.

event.value = getField("FirstName_1").value + " " + getField("MI_1").value + " " + getField("LastName_1").value;

So in my Combo Box labeled “Name of PersonRow1” as the script under Action Mouse Down. This is the only place I can think of to put it. “Name_1Mereged” is hidden. I have about 16 of these.

var c = this.getField("Name of PersonRow1");
c.setItems(["", this.getField("Name_1Merged").valueAsString, this.getField("Name_2Merged").valueAsString, this.getField("Name_3Merged").valueAsString, this.getField("Name_4Merged").valueAsString, this.getField("Name_5Merged").valueAsString, this.getField("Name_6Merged").valueAsString, this.getField("Name_7Merged").valueAsString]);

And to answer one of your questions, on pg 1-2 some of those name rows would be left blank. Like a family of 4 then 5-7 would be blank. And I don’t know the code to check if blank. But am I running these codes in the wrong places?
Thank you