Avatar

Level 2

Hi JBrill1970,

I have had a look at your document but have not gone through your script. I have adapted your information to the script I use. Unfortunately the links above have broken due to Adobe changing the way they do things.

I created three drop-down lists:

  • Country - adding the list of countries to the List items
  • State - adding a placeholder "Select a State" to the List Items which will be populated once a Country is selected
  • County - adding a placeholder "Select a County" to the List items which will be populated once a State is selected

I inserted two ScriptObjects:

  • CountryState
  • StateCounty

CountryState:

  • In the object's Script Editor window I declared a variable which lists the Countries as they are listed in the List Items for the Country drop-down and set up a function to populate the State drop down:

var oCountryStateLists = {


"Country 1": [ ["State 1", "State 1"], ["State 2", "State 2"]],


"Country 2": [ ["State 3", "State 3"], ["State 4", "State 4"]],


"Country 3": [ ["State 5", "State 5"], ["State 6", "State 6"]],


"Country 4": [ ["State 7", "State 7"], ["State 8", "State 8"]]


};




////////////////


// SetStateEntries()


//


// Function for setting the Letters list based on the Country selection value


//


// This function is specifically setup to be called from the Change Event


// of the Country List.  It will not work from another event because the


// "xfa.event.change" parameter is used


//


function SetStateEntries()


{


  // Since entries are added one at a time it is necessary to clear out the list


   State.clearItems();


  // The ComboBox value is not dependent on the list selection so we


  // have to also clear this


   State.rawValue = null;


  


   // Grab the Letters list from the master list and loop over it to fill


   // the List Field


   var aState = oCountryStateLists[xfa.event.change];


   if(aState && aState.length)


   {


      for(var i=0;i<aState.length;i++)


        State.addItem(aState[i][0],aState[i][1].toString());


   }


}


  • On the Country drop-down item I created a Change event in the Script Editor window for JavaScript to run at Client calling the ScriptObject above:

CountryState.SetStateEntries();

This process is repeated for the State drop-down object and the StateCounty Script object:


form1.#subform[0].DropDownChoices.#variables[0].CountryState - (JavaScript, client)




var oCountryStateLists = {


"Country 1": [ ["State 1", "State 1"], ["State 2", "State 2"]],


"Country 2": [ ["State 3", "State 3"], ["State 4", "State 4"]],


"Country 3": [ ["State 5", "State 5"], ["State 6", "State 6"]],


"Country 4": [ ["State 7", "State 7"], ["State 8", "State 8"]]




};




////////////////


// SetStateEntries()


//


// Function for setting the Letters list based on the Country selection value


//


// This function is specifically setup to be called from the Change Event


// of the Country List.  It will not work from another event because the


// "xfa.event.change" parameter is used


//


function SetStateEntries()


{


  // Since entries are added one at a time it is necessary to clear out the list


   State.clearItems();


  // The ComboBox value is not dependent on the list selection so we


  // have to also clear this


   State.rawValue = null;


  


   // Grab the Letters list from the master list and loop over it to fill


   // the List Field


   var aState = oCountryStateLists[xfa.event.change];


   if(aState && aState.length)


   {


      for(var i=0;i<aState.length;i++)


        State.addItem(aState[i][0],aState[i][1].toString());


   }


}


...and on the State drop-down Script Editor window for JavaScript to run at Client:


form1.#subform[0].DropDownChoices.State::change - (JavaScript, client)






StateCounty.SetCountyEntries();


Capture1.jpg

Once set up these script objects can be re-used in other livecycle files. In setting up major lists I think I used a spreadsheet with the Concatenate function.

Good luck. I am happy to send you a copy of the file I created if you want to leave an email address (break the email address up and I will put it back together), or to try and answer any further questions that you have if any of the above is not clear enough. As for your script hopefully someone cleverer than I will be able to work out what was going wrong on the second drop-down otherwise, if I get the chance, I will see if I can make it work but no guarantees!

Greig