Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to populate one dropdown list based on selection in another dropdown list

New Here ,
Nov 12, 2022 Nov 12, 2022

I have 2 dropdown lists. One is named City and the other is State. I want to populate the City with a list of specific cities based and the selected State. I have read several posts in the discussions and I have used the codes in them. However, the validation keeps rejecting the code saying there is an error in the code. I can't see where there is an error. Here is the code:

if(event.value == " ")

this.getField("Trip.Origin.State.Row1").setItems([" "]);

//Illinois

else if(event.value == "IL")

this.getField("Trip.Origin.State.Row1").setItems([" "]);

//Indiana

else if(event.value == "IN")

this.getField("Trip.Origin.State.Row1").setItems(["Butler",”Burns Harbor”,"Crawfordsville","East Chicago"]);

//Kentucky

else if(event.value == "KY")

this.getField("Trip.Origin.State.Row1").setItems(["Ghent"]);

//Michigan

else if(event.value == "MI")

this.getField("Trip.Origin.State.Row1").setItems(["Monroe"]);

//Ohio

else if(event.value == "OH")

this.getField("Trip.Origin.State.Row1").setItems(["Cleveland",”Coshocton”,"Cuyahoga Heights",”Middletown”,"Newburgh Heights",”Zanesville”]);

//Pennsylvania

else if(event.value == "PA")

this.getField("Trip.Origin.State.Row1").setItems([“Butler”,"Sharon","Wheatland"]);

else this.getField("Trip.Origin.State.Row1").clearItems();

TOPICS
How to , JavaScript , PDF forms
1.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Nov 15, 2022 Nov 15, 2022

Different quotes can happen if you use text editors to copy/paste text like 'Word'.

If you want to show cities when you select state then you need to use script in "State" field not '"City" (you can use script as validation). Also make sure you are setting items in correct field, for example in your script you are setting items in "Trip.Origin.State.Row1" but if you use script in "State" field then you need to change that so it set items in "City" fields.

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 12, 2022 Nov 12, 2022

You are using two different types of quote marks, see this: Butler, "Sharon" , fix that, and it will work.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 15, 2022 Nov 15, 2022

I've only have 1 button on my keyboard for quote marks. How am I getting two different quote marks?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 15, 2022 Nov 15, 2022

Do I run this in the City's custom validation script or the custom calculation script? I've tried in the validation script, but nothing happens. I don't get any choices in the City field regardless of which State I choose.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 15, 2022 Nov 15, 2022

Different quotes can happen if you use text editors to copy/paste text like 'Word'.

If you want to show cities when you select state then you need to use script in "State" field not '"City" (you can use script as validation). Also make sure you are setting items in correct field, for example in your script you are setting items in "Trip.Origin.State.Row1" but if you use script in "State" field then you need to change that so it set items in "City" fields.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 15, 2022 Nov 15, 2022
LATEST

Thanks. Working great now.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines