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

How to create a multi-lined text field based on a drop down selection

moreno2194
Registered: Feb 15 2011
Posts: 7
Answered

I would like to create a multi-lined text field that automatically populates based on a drop down selection.
 
I am using Acrobat 8 Professional the drop down box name is locationNames, it has 7 options; San Joaquin/Castaic Room, San Luis Room, Delta Room, Environmental Services, Joint Operations Center, Bonderson Hearing Room, and Headquarters Auditorium. The text field box name is locationDetails, I would like it to populate
 
"1721 13th Street
Sacramento, CA 95814"
for the first 3 options
 
"3500 Industrial Blvd.
West Sacramento, CA 95691"
for the 4th
 
"3310 El Camino Ave.
Sacramento, CA 95821"
for the 5th
 
"901 P Street
Sacramento, CA 95814"
for the 6th
 
"1416 9th Street
Sacramento, CA 95814"
for the 7th
 
I've tried a few different samples however when I enter the actual name of the drop down option it gives me an error. Please help. thanks

My Product Information:
Acrobat Pro 8.1, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
Accepted Answer
Begin by setting the export value of each combo box item, with the first set to 0, then next 1, the next 2, ... and the last 6. The point is you want the export value of each item to be unique. Also, set the "Commit selected value immediately" option for the combo box. You can then use code to get the corresponding address based on the selected item's export value. For this you can use the following custom Keystroke JavaScript:

// Custom Keystroke script for combo box
(function () {

if (!event.willCommit) {

// Set up an array of addresses. \r = carriage return
var aAddr = [];
aAddr[0] = "1721 13th Street\rSacramento, CA 95814";
aAddr[1] = "3500 Industrial Blvd.\rWest Sacramento, CA 95691";
aAddr[2] = "3310 El Camino Ave.\rSacramento, CA 95821";
aAddr[3] = "901 P Street\rSacramento, CA 95814";
aAddr[4] = "1416 9th Street\rSacramento, CA 95814";

// Associate export values of combo box items
// to corresponding index of address array
var aIndex = [];
aIndex[0] = 0;
aIndex[1] = 0;
aIndex[2] = 0;
aIndex[3] = 1;
aIndex[4] = 2;
aIndex[5] = 3;
aIndex[6] = 4;

// Get the export value of the selected item
var ex_val = event.changeEx;

// Get the corresponding address
var addr = aAddr[aIndex[ex_val]];

// Populate the text field with the address
getField("locationDetails").value = addr;
}

})();

You could simplify this a bit, but my goal was to make it clear.
antoniovinci
Registered: Feb 16 2011
Posts: 3
George_Johnson wrote:
You could simplify this a bit, but my goal was to make it clear.
Sir, believe or not, you've just saved my life...

Thanx a bunch from an italian PDF-addicted!

:)

moreno2194
Registered: Feb 15 2011
Posts: 7
Thank you!!!! It worked perfectly. I've been working on this for 3 days straight, now I can enjoy my weekend. Hope you do the same. Thanks again!
moreno2194
Registered: Feb 15 2011
Posts: 7
One more question if I can please George. How would it differ if the text field was another drop down and would I list the items in JS or in the actual drop down box options?

For instance I have a list of classes that I want grouped by subject. So I would like a drop down box with the options Admin, Communications, Employee Development. Then each one of those is associated with another drop down box with their own list.

Admin:
Intro to Purchasing
Bid Solicitation & Preparation
Developing the Statement of Work

Communications:
Dialogic Workshop
Effective Workplace Writing

Employee Development:
Career Planning Workshop
Orientation
Appraisal & Development
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
That's actually simpler. You should use a Keystroke script again, something like:

// Custom Keystroke script for combo box
(function () {

if (!event.willCommit) {

// Set up an array for arrays of classes corresponding to export values in this combo box
var aClasses = [];
aClasses[0] = ["Intro to Purchasing", "Bid Solicitation & Preparation", "Developing the Statement of Work"];
aClasses[1] = ["Dialogic Workshop", "Effective Workplace Writing"];
aClasses[2] = ["Career Planning Workshop", "Orientation", "Appraisal & Development"];// Get the export value of the selected item
var ex_val = event.changeEx;

// Populate the combo box field with the classes
getField("cb3").setItems(aClasses[ex_val]);
}

})();


I haven't tested this, but it should work. Replace "cb3" with the name of the secondary combo box you're using.


Acrobat JavaScript: Saving lives and weekends since 1998
moreno2194
Registered: Feb 15 2011
Posts: 7
perfect!! Thanks again
Lori G
Registered: Apr 29 2009
Posts: 9
Hi,

I have a situation just like moreno2194 where I would like to associate our School Names (we have 7 of them) in a drop down menu and then have it bring in the mailing address also. It would mean 3-4 lines of dropdown.

I have tried to figure out the instructions posted here but can't quite put it all together.....I use Acrobat a lot for simple forms but find I am expanding my horizons unintentionally so to speak...can you do a little more breakdown in the steps for a beginner/moderate experienced user?
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
Lori,

The script posted above was for the special situation where more than one item in the combo box had the same address as other items. If in your case the items each have unique addresses, the script could be simplified to something like:

// Custom Keystroke script for combo box
(function () {

if (!event.willCommit) {

// Set up an array of addresses. \r = carriage return
var aAddr = [];
aAddr[0] = "1721 13th Street\rSacramento, CA 95814";
aAddr[1] = "3500 Industrial Blvd.\rWest Sacramento, CA 95691";
aAddr[2] = "3310 El Camino Ave.\rSacramento, CA 95821";
aAddr[3] = "901 P Street\rSacramento, CA 95814";
aAddr[4] = "1416 9th Street\rSacramento, CA 95814";

// Get the export value of the selected item
var ex_val = event.changeEx;

// Get the corresponding address
var addr = aAddr[ex_val];

// Populate the text field with the address
getField("locationDetails").value = addr;
}

})();


Remember that each combo box item has to have an export value set, starting at 0 for the first item and increment by 1 for the subsequent items.
Lori G
Registered: Apr 29 2009
Posts: 9
George,

Exactly where do I lay this script? I am still only getting my school name in the combo box....here is what I have:

School Information Combo Box
In Box Properties I have, as an example for first school:
Item: Alexander Elementary School
Export Value: aAddr[0]
Item List: has all 7 school names
checked box to commit selected value immediately

Under the Validate tab I have checked to run custom validation script,
hit the edit button and pasted the script as follows:

// Custom Keystroke script for combo box
(function () {

if (!event.willCommit) {

// Set up an array of addresses. \r = carriage return
var aAddr = [];
aAddr[0] = "520 Cherry Street\rAdrian, Michigan 49221";
aAddr[1] = "158 South Scott Street\rAdrian, Michigan 49221";
aAddr[2] = "104 Dawes Street\rAdrian, Michigan 49221";
aAddr[3] = "2568 Airport Highway\rAdrian, Michigan 49221";
aAddr[4] = "340 East Church Street\rAdrian, Michigan 49221";
aAddr[4] = "615 Springbrook Avenue\rAdrian, Michigan 49221";
aAddr[4] = "785 Riverside Avenue, Suite 3\rAdrian, Michigan 49221";

// Get the export value of the selected item
var ex_val = event.changeEx;

// Get the corresponding address
var addr = aAddr[ex_val];

// Populate the text field with the address
getField("School Information").value = addr;
}

})();



Do you see anything glaringly wrong?
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
It is written to be a custom Keystroke script for the combo box. On the Format tab, select a category of "Custom" and you'll see where you can enter the script for the Keystroke event.
Lori G
Registered: Apr 29 2009
Posts: 9
O.k., I backed up and re-read what was done and here is what I have:

In SchoolInformation Combo Box
Item: Alexander Elementary School

Export Value:
aAddr[0] = "520 Cherry Street\rAdrian, Michigan 49221";

Checked commit selected value immediately

In SchoolAddress Field I have the following:
Under Options: Checked multiline
Under Format: Custom
Under Custom Keystoke Script:

// Custom Keystroke script for combo box
(function () {

if (!event.willCommit) {

// Set up an array of addresses. \r = carriage return
var aAddr = [];
aAddr[0] = "520 Cherry Street\rAdrian, Michigan 49221";
aAddr[1] = "158 South Scott Street\rAdrian, Michigan 49221";
aAddr[2] = "104 Dawes Street\rAdrian, Michigan 49221";
aAddr[3] = "2568 Airport Highway\rAdrian, Michigan 49221";
aAddr[4] = "340 East Church Street\rAdrian, Michigan 49221";
aAddr[5] = "615 Springbrook Avenue\rAdrian, Michigan 49221";
aAddr[6] = "785 Riverside Avenue, Suite 3\rAdrian, Michigan 49221";

// Get the export value of the selected item
var ex_val = event.changeEx;

// Get the corresponding address
var addr = aAddr[ex_val];

// Populate the text field with the address
getField("SchoolInformation").value = addr;
}

})();



Still not getting anything.

Lori

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
No, the script is for setting the value of separate multiline text field to the address that corresponds to the item selected in the combo box. So you would have to create a text field under the combo box and name it "School Information". You probably should also make it read-only.
Lori G
Registered: Apr 29 2009
Posts: 9
Hi George,

I have the two separate fields now....can you tell me what exactly my export value in my combo box would be for Alexander School for example?
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
Lori,

Sorry, I didn't recognize what you were doing before now. This code assumes that you've set the export value of the first item to 0, the next item to 1, the next to 2, etc.
Lori G
Registered: Apr 29 2009
Posts: 9
Hmmm, I have set my export values in the SchoolInformation combo box to a range from 0 to 6 for the 7 sites.

I have placed the SchoolAddress text field below the School Information combo box and set it to a read only field and placed the script noted above in the format section under Custom Keystroke Script and I am still not getting the information.

Any suggestions?

Are there any special "Actions" I need to set??
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
Lori,

If you are free to email me the form, I'd be happy to take a look at it. You can use: acroscript at gmail dot com
digitalwiz
Registered: Mar 9 2011
Posts: 20
I dont really understand this so i have setup a simple form. 1 combo box and 1 text field.

I pasted this into the text field's "format" "custom Keystroke" area.
// Custom Keystroke script for combo box
(function () {

if (!event.willCommit) {

// Set up an array of addresses. \r = carriage return
var aAddr = [];
aAddr[0] = "1721 13th Street\rSacramento, CA 95814";
aAddr[1] = "3500 Industrial Blvd.\rWest Sacramento, CA 95691";
aAddr[2] = "3310 El Camino Ave.\rSacramento, CA 95821";
aAddr[3] = "901 P Street\rSacramento, CA 95814";
aAddr[4] = "1416 9th Street\rSacramento, CA 95814";

// Associate export values of combo box items
// to corresponding index of address array
var aIndex = [];
aIndex[0] = 0;
aIndex[1] = 0;
aIndex[2] = 0;
aIndex[3] = 1;
aIndex[4] = 2;
aIndex[5] = 3;
aIndex[6] = 4;

// Get the export value of the selected item
var ex_val = event.changeEx;

// Get the corresponding address
var addr = aAddr[aIndex[ex_val]];

// Populate the text field with the address
getField("locationDetails").value = addr;
}

})();

I edited the Add feature inthe combo box assigning an export value of 1, 2, 3, 4 to 4 individual items.

based on this i named my combo box aAddr and my text box aIndex.

I cant get it to work.

What am I missing?

ps i also tried this one. looks less complicated. still no luck.

// Custom Keystroke script for combo box
(function () {

if (!event.willCommit) {

// Set up an array of addresses. \r = carriage return
var aAddr = [];
aAddr[0] = "1721 13th Street\rSacramento, CA 95814";
aAddr[1] = "3500 Industrial Blvd.\rWest Sacramento, CA 95691";
aAddr[2] = "3310 El Camino Ave.\rSacramento, CA 95821";
aAddr[3] = "901 P Street\rSacramento, CA 95814";
aAddr[4] = "1416 9th Street\rSacramento, CA 95814";

// Get the export value of the selected item
var ex_val = event.changeEx;

// Get the corresponding address
var addr = aAddr[ex_val];

// Populate the text field with the address
getField("locationDetails").value = addr;
}

})();

thanks

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
In this example, the name of the text field is "locationDetails", so try naming your text field that. Also, your situation is more like post #8 above, not #2.
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
The accepted answer uses an array with an entry for each choice in the drop down box.

Each entry in the drop down box exports a value from 0 to n for the associated item in the drop down box. This is known as zero based numbering. So the first item in the drop down box has an export value of 0 (zero) and the 2nd item has an export value of 1, and so on. The aAddr array has an element or entry that has a one to one correspondence with the entries in the drop down box. The first name in the drop down box matches the first element of the address array, the second name corresponds with the second element of the array, and son on.

The statement:

// Get the export value of the selected item
var ex_val = event.changeEx;

gets the export value from the drop down box. Note that the first item has an export value of 0 (zero). This is because the elements of an array in most computer languages and scripts start at 0 (zero). So by using the zero based numbering, one can then use that number to retrieve corresponding value in the array.

You could add additional code to show what is happening.

// Custom Keystroke script for combo box
(function () {

if (!event.willCommit) {

// Set up an array of addresses. \r = carriage return
var aAddr = [];
aAddr[0] = "1721 13th Street\rSacramento, CA 95814";
aAddr[1] = "3500 Industrial Blvd.\rWest Sacramento, CA 95691";
aAddr[2] = "3310 El Camino Ave.\rSacramento, CA 95821";
aAddr[3] = "901 P Street\rSacramento, CA 95814";
aAddr[4] = "1416 9th Street\rSacramento, CA 95814";

// Associate export values of combo box items
// to corresponding index of address array
var aIndex = [];
aIndex[0] = 0;
aIndex[1] = 0;
aIndex[2] = 0;
aIndex[3] = 1;
aIndex[4] = 2;
aIndex[5] = 3;
aIndex[6] = 4;

// Get the export value of the selected item
var ex_val = event.changeEx;

// open JS console
console.show();
console.clear();
// show value of selected item:
console.println('Value of selected item: " + ex_val;

// Get the corresponding address
var addr = aAddr[aIndex[ex_val]];

// display the corresponding address
console.println('Address: ' + addr);

// Populate the text field with the address
getField("locationDetails").value = addr;
}

})();

Have you looked at the results of your changes?
Do they match what you expected?
Are they consistently different from what is expected?
What happens for the first and last items in the drop down box?

George Kaiser

digitalwiz
Registered: Mar 9 2011
Posts: 20
Thanks both of you,

You are correct its more like post #8. I have tried using that script and i determined the same that my text box should be named "locationDetails".

I also figured that i needed to paste the JS into the combo box keystroke and not the Text box. though that seems counter intuitive.

Im tyring to understand this example as a means to make my company eval form, i listed that challenge in another forum post.

In the end all i have gotted in the location details text box is "undefined".

thanks

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
> I pasted this into the text field's "format" "custom Keystroke" area.Also, this is the custom Keystroke script for the combo box, not the text field.
digitalwiz
Registered: Mar 9 2011
Posts: 20
My combo box is currently named eval.

thanks

digitalwiz
Registered: Mar 9 2011
Posts: 20
George_Johnson wrote:
> I pasted this into the text field's "format" "custom Keystroke" area.Also, this is the custom Keystroke script for the combo box, not the text field.
what did you paste into the text fields "format" Keystroke area?

Also in the combo box the export values are typed like this: aAddr[0]

and the next items ev is aAddr[1] and so forth

thanks

digitalwiz
Registered: Mar 9 2011
Posts: 20
I'm sorry to say that this stuff just doesnt appear to work. I'm obviously a novice but if you cant make a 2 item relationship work with the JS that i see little value with these programming options.

I started over. 1 combo box, 1 text box.

I pasted the following into the combo box, format, keystroke
// Custom Keystroke script for combo box
(function () {

if (!event.willCommit) {

// Set up an array of addresses. \r = carriage return
var aAddr = [];
aAddr[0] = "1721 13th Street\rSacramento, CA 95814";
aAddr[1] = "3500 Industrial Blvd.\rWest Sacramento, CA 95691";
aAddr[2] = "3310 El Camino Ave.\rSacramento, CA 95821";
aAddr[3] = "901 P Street\rSacramento, CA 95814";
aAddr[4] = "1416 9th Street\rSacramento, CA 95814";

// Get the export value of the selected item
var ex_val = event.changeEx;

// Get the corresponding address
var addr = aAddr[ex_val];

// Populate the text field with the address
getField("locationDetails").value = addr;
}

})();

I named my text box "locationDetails" without the quotes.

I added 4 value items for my combo box

CSA with ev of aAddr[0]
IT with ev of aAddr[1]
HR with ev of aAddr[2]
CM with ev of aAddr[3]

all the text box says is "undefined".

anything obvious that im doing wrong?

thanks

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
Be sure to set the combo box option of "Commit selected value immediately" on the Options tab. This definitely works, so if you get stuck, it may help to post a sample somewhere (e.g., Acrobat.com) so we can take a look.
digitalwiz
Registered: Mar 9 2011
Posts: 20
thanks George,

I have that selected for each item. Still just get undefined.

So if you did exactly what i did in my previous post then i must be missing something obvious. What did you name the combo box?

thanks

digitalwiz
Registered: Mar 9 2011
Posts: 20
I'd be happy to email it to you george.

thanks

odalaigh
Registered: Jul 1 2011
Posts: 1
I would like to do something similar.. but I would like to have the array editable by the user.. is this possible?

something like this..

(function () {

if (!event.willCommit) {

// Set up an array of addresses. \r = carriage return
var aAdd1 = [];
aAdd1[0] = "1721 13th Street\rSacramento, CA 95814";
aAdd1[1] = "3500 Industrial Blvd.\rWest Sacramento, CA 95691";
aAdd1[2] = "3310 El Camino Ave.\rSacramento, CA 95821";
aAdd1[3] = "901 P Street\rSacramento, CA 95814";
aAdd1[4] = "1416 9th Street\rSacramento, CA 95814";

// Set up an array of addresses. \r = carriage return
var aAdd2 = [];
aAdd2[0] = "Red";
aAdd2[1] = "Green";
aAdd2[2] = "Blue";
aAdd2[3] = "Yellow";
aAdd2[4] = "Purple";

// Get the export value of the selected item
var ex_val = event.changeEx;

// Get the corresponding address
var add1 = aAdd1[ex_val];

// Get the corresponding address
var add2 = aAdd2[ex_val];

// Populate the text field with the address
getField("locationDetails").value = add1;

// Populate the text field with the address
getField("color").value = add2;
}

})();

and have the user be-able to change the color and save it..

bburwell
Registered: Sep 7 2011
Posts: 1
George, I noticed you were able to help many with questions relating to using drop boxes.

My question is this if you do not mind.

I have a employment form we use for disciplinary action, I have it as a pdf, loaded it into acrobat 9 (MAC) and i am adding fields. When i get to the drop box that would list all the available reason for getting a disciplinary action it will not display the text multi-line as I am assuming it wants short text selection. I imagine what I would need to do is have a short selection (i.e.) 11.2.1 and then somehow have a text box below display the description(multi-lines ea) of 11.2.1 there are around 80 of them to enter and this is why I want to go with a drop box unless you have a better suggestion . (btw the 11.2.1 goes sequentially 11.2.2 11.2.3 ... )


I would very much appreciate any help you could give me, I am not versed in scripts or programming so I would just need to know how to do what you perhaps suggest.

Thanks very much ... Brian
bburwell [at] gmail [dot] com

Brian Burwell
Alberta, Canada

moreno2194
Registered: Feb 15 2011
Posts: 7
I'd like to populate a text field with different text based on the drop down selection. Not all options will have text. How do i change it to give values that I can base the text field on? For example if "Developing the Scope of Work" in aClasses[1] is selected I'd like to populate a note that says "Participants should bring a Scope of Work to class for use in one of the exercises" in text field "Text1" does that make sense?

This is the java i used for the drop down.

// Custom Keystroke script for combo box
(function () {

if (!event.willCommit) {

// Set up an array for arrays of classes corresponding to export values in this combo box
var aClasses = [];
aClasses[0] = [""];

aClasses[1] = ["CAL Card Training","Developing the Scope of Work","Introduction to Purchasing","Training Coordinator Workshop"];

aClasses[2] = ["Dialogic Workshop", "Effective Workplace Writing", "Radio Communications & Usage","Technical Writing for Non-Technical Audience", "Training for Trainers", "Working with the News Media"];aClasses[3] = ["Appraisal & Development Employee TRG-REP.", "Appraisal & Development Mgr/Sup/Confid.", "Career Planning Workshop", "Civil Service Exam Prep.", "Disc. Awareness & Sexual Harassment Prev-REP", "DWR Orientation"];aClasses[4] = ["Climate Literacy 101", "Economics of Water", "Employee Environ. Responsibilty", "Environmental Laws & Responsibilty", "Non-Detects & Data Analysis: Stat Methods", "Time Series Analysis & Forecasting","QA/QC Applied Environmental Stats", "QA/QC QA For Water Quality Monitoring", "Water Law", "Water Quality Basics", "Water Quality Monitoring"];aClasses[5] = ["Flood Fighting Methods", "Flood Information Specialist", "Response Info Management System","SEMS/NIMS/ICS Executive Course", "SEMS/NIMS/ICS General Staff Course", "SEMS/NIMS/ICS Int. & Adv. Course Only", "SEMS/NIMS/ICS Introductory Course", "SEMS/NIMS/ICS Staff Course", "Training 4 Trnrs Flood Fighting Methods"];aClasses[6] = ["1st AID/Adult CPR/AED","Confined Space Entry Awareness", "DWR Safety Program", "Substance Abuse Trng.- REP", "Worplace Safety Training"];aClasses[7] = ["Excel 2007 Level 1", "Excel 2007 Level 2", "Intro to GIS", "Word 2007 Level 1", "Word 2007 Level 2"];

aClasses[8] = ["DWR Leadperson Workshop", "EE Assistance Prog for Mngrs/Supvs", "Performance Management-Refresher", "Sexual Harassment Prevention Mgr/Sup/Conf-Refresher", "Substance Abuse Confirmer Training", "Substance Abuse Mgr &Supv"];aClasses[9] = ["Commodity Requisitioning", "Time Recorder Workshop", "Training Even Processing"];aClasses[10] = ["Applied Math","Civil Engineer Survey Exam Prep","Flow Measurement/Rating Curve Generation", "Fundamnetals of Surveying", "Groundwater, Introduction", "Hydraulics", "Hydrology Basics", "Project Planning for Real Estate & Surv Serv", "SWP Operations & The Delta","Aqueduct Systems", "ARC Flash/Shock Hazard Awareness", "Electrical Print Reading", "Electricity, Advance", "Electricity, Basic", "Friction & Anti-friction Bearings", "Industrial Hydraulics Seminar", "Introduction to ARC Welding", "National Electric Codebook", "Positive & Non-Pos. Displacement Pumps", "Protective Relay Application", "SWP Power Resources & Power Mgmt.", "Voltage Regulators", "Water Treatment","Welding Certification", "Concrete Technology", "Soils & Earthwork Construction"];aClasses[11] = [];// Get the export value of the selected item
var ex_val = event.changeEx;

// Populate the text field with the address
getField("AdminClasses").setItems(aClasses[ex_val]);
}

})();