Skip to main content
Known Participant
November 13, 2022
Answered

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

  • November 13, 2022
  • 1 reply
  • 1778 views

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();

This topic has been closed for replies.
Correct answer Nesa Nurani

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.

1 reply

Nesa Nurani
Community Expert
Community Expert
November 13, 2022

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

Known Participant
November 16, 2022

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