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

Javascript Array DropDown: basic

Torvik
Registered: Mar 14 2007
Posts: 25

Any ideas why this doens't work?

var RoomNum=new Array(5)
RoomNum[0]="1";
RoomNum[1]="2";
RoomNum[2]="3";
RoomNum[3]="4";
RoomNum[4]="5";
RoomNum[5]="6";

if (DropDownList1.rawValue == 0) {
DropDownList4.addItem (RoomNum);
}

(Instead of giving me the 6 numbers, I just get the word "empty")
Thanks so much!
Alan

DominicanPete
Registered: Jan 4 2008
Posts: 41
My guess here is (from some trial and error coding) is that you can add only 1 item at a time using addItem. If you need to populate with multiple values, write a loop that will execute the add item for each value in the array. An example would be:

var RoomNum=new Array(5)
var iter = 0

RoomNum[0]="1";
RoomNum[1]="2";
RoomNum[2]="3";
RoomNum[3]="4";
RoomNum[4]="5";
RoomNum[5]="6";

if (DropDownList1.rawValue == 0) {
while (iter < 5) {
DropDownList4.addItem( RoomNum[iter]);
iter = iter + 1;
}
}

My guess on your assignment is that 'RoomNum' in and of itself is indeed empty - thus your result. Add each drop box item as above, and it shoulda-oughta work. Good luck!
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
You need to add each item one at time, you can not use Acrobat's JS "addArray()" method. You could also make your code more easily maintained by using the length property of the array so as more items are added to the array you do not need to change anything elsewhere.


var RoomNum = new Array("1", "2", "3", "4", "5");

if(DropDownList1.rawValue == 0) {
for (i = 0; i < RoomNum.length; i++) {
DropDownList4.addItem(RoomNum[i]);
} // end for
} // end if

George Kaiser

Torvik
Registered: Mar 14 2007
Posts: 25
Ok. Got this working. I'm able make a dropdown with the array.
Now how do I make the value reflect the item selected? i.e. If a person selects "2", how do I let other boxes interact with that selection.

I wonder if I'm going to have trouble with "mixing magics". I mean, this particular dropdown is made possible by using JS, right? Will FormCalc items be able to interact with it? Right now I have a simple numeric field that says "dropdownlist2" in order to show what the value from the dropdown has been selected. The dropdown is working now, but this numeric field stays blank. Is it possible for FormCalc to recognize the fruit of JS?

Thanks so much, folks! Couldn't do this project without ya!
Alan
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]);
}

})();