State / Province Dropdown list code for LiveCycle ***JavaScript***

16 views
Skip to first unread message

adamjoel79

unread,
Dec 4, 2020, 2:10:25 PM12/4/20
to Adobe LiveCycle Developers
Hey all. I was making a Bill of Lading for a client and I figured I would share something I made for it as I know some people look for something like this all the time.

In the dropdown list it will display the full name of each Province (Canada) or State (USA) and then once selected it will convert it to the 2 Letter ISO 3166-2 code and fill in the "Country" field value (Canada or USA). It will also display the full name of the Province or State for the tool tip if you mouse over the selection. You can re-order the list for US states first if you want to. It is currently Canada first, then USA but it is alphabetically sorted.

Hope you all find it useful.

- Adam :-D



// OPTIONAL: "Change" event - This keeps field to 30 characters if manual text entry is desired. Adjust for more or less to taste.

if (xfa.event.newText.length > 30) {  
  xfa.event.change = "";  
}



// OPTIONAL: "Enter" event - This opens the dropdown list on entry so you can use the "AutoComplete" feature.

xfa.host.openList("$");



// REQUIRED: Create a dropdown list (name does not matter much) and then a text field or dropdown list called Country. Copy and paste the Province and State names below to the dropdown list menu. The space between Yukon and Alabama is intentionally kept to visibly seperate the Canada / USA entries.



British Columbia
Manitoba
New Brunswick
Newfoundland / Labrador
Northwest Territories
Nova Scotia
Nunavut
Ontario
Prince Edward Island
Quebec
Saskatchewan
Yukon
 
Alabama
Alaska
Arizona
Arkansas
California
Colorado
Connecticut
Delaware
Florida
Georgia
Hawaii
Idaho
Illinois
Indiana
Iowa
Kansas
Kentucky
Louisiana
Maine
Maryland
Massachusetts
Michigan
Minnesota
Mississippi
Missouri
Montana
Nebraska
Nevada
New Hampshire
New Jersey
New Mexico
New York
North Carolina
North Dakota
Ohio
Oklahoma
Oregon
Pennsylvania
Rhode Island
South Carolina
South Dakota
Tennessee
Texas
Utah
Vermont
Virginia
Washington
West Virginia
Wisconsin
Wyoming


// REQUIRED: Place Below script in "Exit" event of the dropdown list.



if (this.resolveNode("$").rawValue == "Alberta") {
  this.resolveNode("$").rawValue = "AB";
  this.resolveNode("Country").rawValue = "Canada";
  this.resolveNode("$").assist.toolTip.value = "Alberta";
}
if (this.resolveNode("$").rawValue == "British Columbia") {
  this.resolveNode("$").rawValue = "BC";
  this.resolveNode("Country").rawValue = "Canada";
  this.resolveNode("$").assist.toolTip.value = "British Columbia";
}
if (this.resolveNode("$").rawValue == "Manitoba") {
  this.resolveNode("$").rawValue = "MB";
  this.resolveNode("Country").rawValue = "Canada";
  this.resolveNode("$").assist.toolTip.value = "Manitoba";
}
if (this.resolveNode("$").rawValue == "New Brunswick") {
  this.resolveNode("$").rawValue = "NB";
  this.resolveNode("Country").rawValue = "Canada";
  this.resolveNode("$").assist.toolTip.value = "New Brunswick";
}
if (this.resolveNode("$").rawValue == "Newfoundland / Labrador") {
  this.resolveNode("$").rawValue = "NL";
  this.resolveNode("Country").rawValue = "Canada";
  this.resolveNode("$").assist.toolTip.value = "Newfoundland / Labrador";
}
if (this.resolveNode("$").rawValue == "Northwest Territories") {
  this.resolveNode("$").rawValue = "NT";
  this.resolveNode("Country").rawValue = "Canada";
  this.resolveNode("$").assist.toolTip.value = "Northwest Territories";
}
if (this.resolveNode("$").rawValue == "Nova Scotia") {
  this.resolveNode("$").rawValue = "NS";
  this.resolveNode("Country").rawValue = "Canada";
  this.resolveNode("$").assist.toolTip.value = "Nova Scotia";
}
if (this.resolveNode("$").rawValue == "Nunavut") {
  this.resolveNode("$").rawValue = "NU";
  this.resolveNode("Country").rawValue = "Canada";
  this.resolveNode("$").assist.toolTip.value = "Nunavut";
}
if (this.resolveNode("$").rawValue == "Ontario") {
  this.resolveNode("$").rawValue = "ON";
  this.resolveNode("Country").rawValue = "Canada";
  this.resolveNode("$").assist.toolTip.value = "Ontario";
}
if (this.resolveNode("$").rawValue == "Prince Edward Island") {
  this.resolveNode("$").rawValue = "PE";
  this.resolveNode("Country").rawValue = "Canada";
  this.resolveNode("$").assist.toolTip.value = "Prince Edward Island";
}
if (this.resolveNode("$").rawValue == "Quebec") {
  this.resolveNode("$").rawValue = "QC";
  this.resolveNode("Country").rawValue = "Canada";
  this.resolveNode("$").assist.toolTip.value = "Quebec";
}
if (this.resolveNode("$").rawValue == "Saskatchewan") {
  this.resolveNode("$").rawValue = "SK";
  this.resolveNode("Country").rawValue = "Canada";
  this.resolveNode("$").assist.toolTip.value = "Saskatchewan";
}
if (this.resolveNode("$").rawValue == "Yukon") {
  this.resolveNode("$").rawValue = "YT";
  this.resolveNode("Country").rawValue = "Canada";
  this.resolveNode("$").assist.toolTip.value = "Yukon";
}



if (this.resolveNode("$").rawValue == " ") {
  this.resolveNode("$").rawValue = " ";
  this.resolveNode("Country").rawValue = " ";
  this.resolveNode("$").assist.toolTip.value = " ";
}
if (this.resolveNode("$").rawValue == null) {
  this.resolveNode("$").rawValue = "";
  this.resolveNode("Country").rawValue = "";
  this.resolveNode("$").assist.toolTip.value = "";
}



if (this.resolveNode("$").rawValue == "Alabama") {
  this.resolveNode("$").rawValue = "AL";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "Alabama";
}
if (this.resolveNode("$").rawValue == "Alaska") {
  this.resolveNode("$").rawValue = "AK";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "Alaska";
}
if (this.resolveNode("$").rawValue == "Arizona") {
  this.resolveNode("$").rawValue = "AZ";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "Arizona";
}
if (this.resolveNode("$").rawValue == "Arkansas") {
  this.resolveNode("$").rawValue = "AR";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "Arkansas";
}
if (this.resolveNode("$").rawValue == "California") {
  this.resolveNode("$").rawValue = "CA";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "California";
}
if (this.resolveNode("$").rawValue == "Colorado") {
  this.resolveNode("$").rawValue = "CO";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "Colorado";
}
if (this.resolveNode("$").rawValue == "Connecticut") {
  this.resolveNode("$").rawValue = "CT";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "Connecticut";
}
if (this.resolveNode("$").rawValue == "Delaware") {
  this.resolveNode("$").rawValue = "DE";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "Delaware";
}
if (this.resolveNode("$").rawValue == "Florida") {
  this.resolveNode("$").rawValue = "FL";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "Florida";
}
if (this.resolveNode("$").rawValue == "Georgia") {
  this.resolveNode("$").rawValue = "GA";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "Georgia";
}
if (this.resolveNode("$").rawValue == "Hawaii") {
  this.resolveNode("$").rawValue = "HI";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "Hawaii";
}
if (this.resolveNode("$").rawValue == "Idaho") {
  this.resolveNode("$").rawValue = "ID";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "Idaho";
}
if (this.resolveNode("$").rawValue == "Illinois") {
  this.resolveNode("$").rawValue = "IL";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "Illinois";
}
if (this.resolveNode("$").rawValue == "Indiana") {
  this.resolveNode("$").rawValue = "IN";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "Indiana";
}
if (this.resolveNode("$").rawValue == "Iowa") {
  this.resolveNode("$").rawValue = "IA";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "Iowa";
}
if (this.resolveNode("$").rawValue == "Kansas") {
  this.resolveNode("$").rawValue = "KS";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "Kansas";
}
if (this.resolveNode("$").rawValue == "Kentucky") {
  this.resolveNode("$").rawValue = "KY";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "Kentucky";
}
if (this.resolveNode("$").rawValue == "Louisiana") {
  this.resolveNode("$").rawValue = "LA";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "Louisiana";
}
if (this.resolveNode("$").rawValue == "Maine") {
  this.resolveNode("$").rawValue = "ME";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "Maine";
}
if (this.resolveNode("$").rawValue == "Maryland") {
  this.resolveNode("$").rawValue = "MD";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "Maryland";
}
if (this.resolveNode("$").rawValue == "Massachusetts") {
  this.resolveNode("$").rawValue = "MA";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "Massachusetts";
}
if (this.resolveNode("$").rawValue == "Michigan") {
  this.resolveNode("$").rawValue = "MI";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "Michigan";
}
if (this.resolveNode("$").rawValue == "Minnesota") {
  this.resolveNode("$").rawValue = "MN";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "Minnesota";
}
if (this.resolveNode("$").rawValue == "Mississippi") {
  this.resolveNode("$").rawValue = "MS";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "Mississippi";
}
if (this.resolveNode("$").rawValue == "Missouri") {
  this.resolveNode("$").rawValue = "MO";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "Missouri";
}
if (this.resolveNode("$").rawValue == "Montana") {
  this.resolveNode("$").rawValue = "MT";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "Montana";
}
if (this.resolveNode("$").rawValue == "Nebraska") {
  this.resolveNode("$").rawValue = "NE";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "Nebraska";
}
if (this.resolveNode("$").rawValue == "Nevada") {
  this.resolveNode("$").rawValue = "NV";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "Nevada";
}
if (this.resolveNode("$").rawValue == "New Hampshire") {
  this.resolveNode("$").rawValue = "NH";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "New Hampshire";
}
if (this.resolveNode("$").rawValue == "New Jersey") {
  this.resolveNode("$").rawValue = "NJ";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "New Jersey";
}
if (this.resolveNode("$").rawValue == "New Mexico") {
  this.resolveNode("$").rawValue = "NM";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "New Mexico";
}
if (this.resolveNode("$").rawValue == "New York") {
  this.resolveNode("$").rawValue = "NY";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "New York";
}
if (this.resolveNode("$").rawValue == "North Carolina") {
  this.resolveNode("$").rawValue = "NC";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "North Carolina";
}
if (this.resolveNode("$").rawValue == "North Dakota") {
  this.resolveNode("$").rawValue = "ND";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "North Dakota";
}
if (this.resolveNode("$").rawValue == "Ohio") {
  this.resolveNode("$").rawValue = "OH";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "Ohio";
}
if (this.resolveNode("$").rawValue == "Oklahoma") {
  this.resolveNode("$").rawValue = "OK";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "Oklahoma";
}
if (this.resolveNode("$").rawValue == "Oregon") {
  this.resolveNode("$").rawValue = "OR";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "Oregon";
}
if (this.resolveNode("$").rawValue == "Pennsylvania") {
  this.resolveNode("$").rawValue = "PA";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "Pennsylvania";
}
if (this.resolveNode("$").rawValue == "Rhode Island") {
  this.resolveNode("$").rawValue = "RI";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "Rhode Island";
}
if (this.resolveNode("$").rawValue == "South Carolina") {
  this.resolveNode("$").rawValue = "SC";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "South Carolina";
}
if (this.resolveNode("$").rawValue == "South Dakota") {
  this.resolveNode("$").rawValue = "SD";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "South Dakota";
}
if (this.resolveNode("$").rawValue == "Tennessee") {
  this.resolveNode("$").rawValue = "TN";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "Tennessee";
}
if (this.resolveNode("$").rawValue == "Texas") {
  this.resolveNode("$").rawValue = "TX";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "Texas";
}
if (this.resolveNode("$").rawValue == "Utah") {
  this.resolveNode("$").rawValue = "UT";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "Utah";
}
if (this.resolveNode("$").rawValue == "Vermont") {
  this.resolveNode("$").rawValue = "VT";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "Vermont";
}
if (this.resolveNode("$").rawValue == "Virginia") {
  this.resolveNode("$").rawValue = "VA";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "Virginia";
}
if (this.resolveNode("$").rawValue == "Washington") {
  this.resolveNode("$").rawValue = "WA";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "Washington";
}
if (this.resolveNode("$").rawValue == "West Virginia") {
  this.resolveNode("$").rawValue = "WV";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "West Virginia";
}
if (this.resolveNode("$").rawValue == "Wisconsin") {
  this.resolveNode("$").rawValue = "WI";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "Wisconsin";
}
if (this.resolveNode("$").rawValue == "Wyoming") {
  this.resolveNode("$").rawValue = "WY";
  this.resolveNode("Country").rawValue = "USA";
  this.resolveNode("$").assist.toolTip.value = "Wyoming";
}



Reply all
Reply to author
Forward
0 new messages