Expand my Community achievements bar.

Populate text box from dynamic drop down list

Avatar

Former Community Member
I have different posts about how to populate a drop-down list from another drop down, and how to populate a text from a drop down list. But my situation is different. I have two drop down lists and a text box. What I need is Dropdown2 to populate from Dropdown1 and upon the selection of the new values in Dropdown2, populate a value in Textbox1. I have the drop boxes working but I don't know how to populate the text box from the dynamically populated drop down. Make Sense? ;-)



I have an exit script in dropdown1 for dropdown2 and just need another exit script from dropdown2 for textbox1. My code is posted below for the drop boxes. Can anyone help?



Dropdown2.rawValue = xfa.event.newText;



if (this.rawValue == 0) { //BET Surface Area

Dropdown2.clearItems();

Dropdown2.addItem("Multi-point N2", "0");

Dropdown2.addItem("Single-point N2", "1");

Dropdown2.addItem("Multi-point Kr", "2");

Dropdown2.addItem("Single-point Kr", "3");

Dropdown2.addItem("Single-point Flowsorb", "4");

} else if (this.rawValue == 1){ //Chemisorption

Dropdown2.clearItems();

Dropdown2.addItem("Static Volumetric Chemi", "0");

Dropdown2.addItem("Dynamic Pulse Chemi", "1");

Dropdown2.addItem("Pulse Chemi of Liquid Vapors", "2");

Dropdown2.addItem("TPD", "3");

Dropdown2.addItem("TPR", "4");

Dropdown2.addItem("TPO", "5");

Dropdown2.addItem("Mass Spec Analysis", "6");

Dropdown2.addItem("First Order Kinetics", "7");

} else if (this.rawValue == 2){ //Density

Dropdown2.clearItems();

Dropdown2.addItem("Skeletal Density", "0");

Dropdown2.addItem("Skeletal Density with Temp Control", "1");

Dropdown2.addItem("Mercury Density", "2");

Dropdown2.addItem("Envelope Density", "3");

Dropdown2.addItem("T.A.P. Density", "4");

Dropdown2.addItem("Pore Volume from Density", "5");

Dropdown2.addItem("USP <616> Bulk/Tap Density", "6");

} else if (this.rawValue == 3){ //Particle Size

Dropdown2.clearItems();

Dropdown2.addItem("Light Scattering - Water Dispersion", "0");

Dropdown2.addItem("Light Scattering - Nonaqueous Dispersion", "1");

Dropdown2.addItem("Light scattering - Water dispersion", "2");

Dropdown2.addItem("Sedimentation", "3");

Dropdown2.addItem("Elzone", "4");

Dropdown2.addItem("Elzone - Size Plus Concentration", "5");

Dropdown2.addItem("Elzone - Emission Filters", "6");

Dropdown2.addItem("Dynamic Image Analysis", "7");

Dropdown2.addItem("Sieve's", "8");

Dropdown2.addItem("Nanosize Calculation", "9");

} else if (this.rawValue == 4){ //Pore Size by Gas Adsorption

Dropdown2.clearItems();

Dropdown2.addItem("Adsorption Isotherm", "0");

Dropdown2.addItem("Desorption Isotherm", "1");

Dropdown2.addItem("Adsorption/Desorption Isotherm", "2");

Dropdown2.addItem("Micropore Adsorption Isotherm", "3");

Dropdown2.addItem("Isoteric Heat of Adsorption", "4");

} else if (this.rawValue == 5){ //Pore Size by Mercury Intrusion

Dropdown2.clearItems();

Dropdown2.addItem("Intrusion Analysis", "0");

Dropdown2.addItem("Intrusion/Extrusion Analysis", "1");

Dropdown2.addItem("Hi-Resolution Macropore Analysis", "2");

Dropdown2.addItem("Macropore plus Mesopore Analysis", "3");

Dropdown2.addItem("Special Data Reduction Software", "4");

} else if (this.rawValue == 6){ //Other

Dropdown2.clearItems();

Dropdown2.addItem("Microscopy Analysis", "0");

Dropdown2.addItem("Microscope Pictures", "1");

Dropdown2.addItem("H2 Isotherms", "2");

Dropdown2.addItem("High Pressure Isotherms", "3");

Dropdown2.addItem("Non-Std Lab Analysis", "4");

Dropdown2.addItem("Method Development", "5");

Dropdown2.addItem("Consulting Services", "6");

Dropdown2.addItem("Zeta Potential", "7");

Dropdown2.addItem("Viscosity", "8");

Dropdown2.addItem("pH", "9");

Dropdown2.addItem("Percent Moisture", "10");

Dropdown2.addItem("Specific Gravity", "11");

Dropdown2.addItem("Total Dissolved Solids", "12");

Dropdown2.addItem("Total Suspended Solids", "13");

Dropdown2.addItem("Calibration of Hg Pens", "14");

Dropdown2.addItem("Calibration of TriStar Tubes", "15");

}else if (t
10 Replies

Avatar

Level 5
Dayna:

I would switch to the Change Event, from the Exit Event.

What value do you want in Textbox1 if "Multi-point N2" is selected in Dropdown2?



something like:

Textbox1.rawValue = "My New Text";

in the change event of Dropdown2 should do the trick.



Mark

Avatar

Level 7
Instead of using Nested if statements you might what to use the "switch" statement.



switch (this.rawValue) {



case 0:

//BET Surface Area

Dropdown2.clearItems();

Dropdown2.addItem("Multi-point N2", "0");

Dropdown2.addItem("Single-point N2", "1");

Dropdown2.addItem("Multi-point Kr", "2");

Dropdown2.addItem("Single-point Kr", "3");

Dropdown2.addItem("Single-point Flowsorb", "4");

break;



case 1:

//Chemisorption

Dropdown2.clearItems();

Dropdown2.addItem("Static Volumetric Chemi", "0");

Dropdown2.addItem("Dynamic Pulse Chemi", "1");

Dropdown2.addItem("Pulse Chemi of Liquid Vapors", "2");

Dropdown2.addItem("TPD", "3");

Dropdown2.addItem("TPR", "4");

Dropdown2.addItem("TPO", "5");

Dropdown2.addItem("Mass Spec Analysis", "6");

Dropdown2.addItem("First Order Kinetics", "7");

break;



case 2:

//Density

Dropdown2.clearItems();

Dropdown2.addItem("Skeletal Density", "0");

Dropdown2.addItem("Skeletal Density with Temp Control", "1");

Dropdown2.addItem("Mercury Density", "2");

Dropdown2.addItem("Envelope Density", "3");

Dropdown2.addItem("T.A.P. Density", "4");

Dropdown2.addItem("Pore Volume from Density", "5");

Dropdown2.addItem("USP <616> Bulk/Tap Density", "6");

break;



case 3:

//Particle Size

Dropdown2.clearItems();

Dropdown2.addItem("Light Scattering - Water Dispersion", "0");

Dropdown2.addItem("Light Scattering - Nonaqueous Dispersion", "1");

Dropdown2.addItem("Light scattering - Water dispersion", "2");

Dropdown2.addItem("Sedimentation", "3");

Dropdown2.addItem("Elzone", "4");

Dropdown2.addItem("Elzone - Size Plus Concentration", "5");

Dropdown2.addItem("Elzone - Emission Filters", "6");

Dropdown2.addItem("Dynamic Image Analysis", "7");

Dropdown2.addItem("Sieve's", "8");

Dropdown2.addItem("Nanosize Calculation", "9");

break;



case 4:

//Pore Size by Gas Adsorption

Dropdown2.clearItems();

Dropdown2.addItem("Adsorption Isotherm", "0");

Dropdown2.addItem("Desorption Isotherm", "1");

Dropdown2.addItem("Adsorption/Desorption Isotherm", "2");

Dropdown2.addItem("Micropore Adsorption Isotherm", "3");

Dropdown2.addItem("Isoteric Heat of Adsorption", "4");

break;



case 5:

//Pore Size by Mercury Intrusion

Dropdown2.clearItems();

Dropdown2.addItem("Intrusion Analysis", "0");

Dropdown2.addItem("Intrusion/Extrusion Analysis", "1");

Dropdown2.addItem("Hi-Resolution Macropore Analysis", "2");

Dropdown2.addItem("Macropore plus Mesopore Analysis", "3");

Dropdown2.addItem("Special Data Reduction Software", "4");

break;



case 6:

//Other

Dropdown2.clearItems();

Dropdown2.addItem("Microscopy Analysis", "0");

Dropdown2.addItem("Microscope Pictures", "1");

Dropdown2.addItem("H2 Isotherms", "2");

Dropdown2.addItem("High Pressure Isotherms", "3");

Dropdown2.addItem("Non-Std Lab Analysis", "4");

Dropdown2.addItem("Method Development", "5");

Dropdown2.addItem("Consulting Services", "6");

Dropdown2.addItem("Zeta Potential", "7");

Dropdown2.addItem("Viscosity", "8");

Dropdown2.addItem("pH", "9");

Dropdown2.addItem("Percent Moisture", "10");

Dropdown2.addItem("Specific Gravity", "11");

Dropdown2.addItem("Total Dissolved Solids", "12");

Dropdown2.addItem("Total Suspended Solids", "13");

Dropdown2.addItem("Calibration of Hg Pens", "14");

Dropdown2.addItem("Calibration of TriStar Tubes", "15");

break;



// and so on



default:

app.alert("Unknown test selected: " + test.rawValue");

break;

} // end switch test.rawValue



You can create an exit script for the Dropdown2 box:



if (Dropdown2.rawValue != "") {

newText.rawValue = Dropdown2.rawValue;

} else {

newText.rawValue = "";

}

Avatar

Former Community Member
Each value in dropdown2 corresponds with a part number, so what I want is:



Dropdown1 = BET Surface Area

Dropdown2 = Multi-point N2

Text = 005-01

Avatar

Level 7
First you have to either populate Dropdown2 with an array for each item or use the JavaScript "split([ separator][, limit])" method. It appear you should be providing the necessary leading zeros. Assuming the "501-" is a fixed value and the part number is the number after the first coma in the Dropdown2 export value and the second part of the part number is 2 digits long:.



Using the "split()" method:



var aDropdown2 = Dropdown2.rawValue.split(","); // split Dropdown2 value into an array

if (aDropdown2[1].length == 1) aDropdown2.[1] = "0" + aDropdown2[1]; // add leading zero if necessary to subpart number

Text.rawValue = "501-" + aDropdown2[1]; // build part number



More information about how Dropdown1 is populated or where the first part of the part number comes from.

Avatar

Former Community Member
Mark,



The change event won't work for this scenario. According to LiveCycle Designer Scripting Basics manual, change event does not initiate in response to changes in the object values as a result of calculations or scripts, or by the merging of the form design with data. My dropdown2 is a result of scripting.

Avatar

Level 5
I am using Designer 8.0, and have been successful building dropdowns from data returned from database calls, then populating text fields off of the selections.

While not 100% match to your situation, we have found that the change event of the dropdown fields to be a quite solid trigger in our designs.



You can trap and examine these properties in the change event:

this.rawValue - (may be null on first selection)

xfa.event.newText - (will be the actual text value of the selection)

this.boundItem(xfa.event.change) - (will be the index or bound value of the selection)



Best Regards

Mark

Avatar

Level 7
You can use the following FromCalc scripts:



Field Dropdown1:

Value = first 3 characters of item number

Text = user selection text



Value:| Text



501 | "BET SurfaceArea"

502 | "Chemisorption"

etc



"exit" script for DropBox1:



Dropdown2.clearItems();

if (this.rawValue == 501) //BET Surface Area

Dropdown2.addItem("Multi-point N2", "00");

Dropdown2.addItem("Single-point N2", "01");

Dropdown2.addItem("Multi-point Kr", "02");

Dropdown2.addItem("Single-point Kr", "03");

Dropdown2.addItem("Single-point Flowsorb", "04")

elseif (this.rawValue == 502) //Chemisorption

Dropdown2.addItem("Static Volumetric Chemi", "0");

Dropdown2.addItem("Dynamic Pulse Chemi", "1");

Dropdown2.addItem("Pulse Chemi of Liquid Vapors", "2");

Dropdown2.addItem("TPD", "3");

Dropdown2.addItem("TPR", "4");

Dropdown2.addItem("TPO", "5");

Dropdown2.addItem("Mass Spec Analysis", "6");

Dropdown2.addItem("First Order Kinetics", "7");

else

xfa.host.messageBox(Concat("Unknown selection Dropdown1: ", this.rawValue))

endif



Field Dropdown2:

populated by "exit" script of DropBox1

Value = second part of item number

Test = user selection text



Field for the PartNumber:

Calculation script:



if (HasValue(Dropdown1) and HasValue(Dropdown2) ) then

this.rawValue = Concat(Dropdown1.rawValue, "-", Dropdown2.rawValue)

else

this.rawValue = ""

endif

Avatar

Former Community Member
Geo,



thanks for the response. Um the only thing with your last suggestion that doesn't work for me is that for every suggestion that populates in dropdown2 has a unique text result. I.e. "005-01" is the value for Multi-point N2, "005-00" is the value for Single-point N2, "005-02" is the result for Multi-point Kr, and so on. So basically I have 56 choices in dropdown2 and 56 results to go in the text-box.



Before Mark's last suggestion, I tried to maybe make 7 different arrays and then the size of the arrays vary. I've just finished the arrays and haven't coded any additional material yet. I'll have to see how it goes.

Avatar

Level 5
Dayna:

I think you were close.

If you try this - In Change event of Dropdown1



Dropdown2.rawValue = xfa.event.newText;



if (this.boundItem(xfa.event.change) == 0) { //BET Surface Area

Dropdown2.clearItems();

Dropdown2.addItem("Multi-point N2", "005-01");

Dropdown2.addItem("Single-point N2", "005-00");

Dropdown2.addItem("Multi-point Kr", "2");

Dropdown2.addItem("Single-point Kr", "3");

Dropdown2.addItem("Single-point Flowsorb", "4");

} else if (this.boundItem(xfa.event.change) == 1){ //Chemisorption

Dropdown2.clearItems(); .......



Put your values in the index portion - see "Multi-point N2", and "Single-point N2" above.



In the Dropdown2 change event, place this code:

TextBox3.rawValue = this.boundItem(xfa.event.change);



You should see "005-01" in TextBox3, if you select

"BET Surface Area"

Then

"Multi-point N2".



Best Wishes

Mark

Avatar

Former Community Member
Mark.



Thanks so much. That worked. I can't believe I was so close to it in the beginning. You and Geo made me think of things I had not even considered. Best Wishes to you, as Well! :-)