I am using trying to use jQuery .change() to create two <select> elements whereby the first <select id="state"> is for generating a list of states and the second <select id="city"> is to generate a list of cities.
The values of states and cities will not be hard-coded but generated from values pass from web services.
The list of options to be generated is supposed to work like this: if user selects state from <select id="state"> the selected value will be pass to a web service to retrieve the list to generate the <select id="city"> for cities.
I’m really not sure how to implement this. Can anyone please advise me?
it should look something like
This can get you started however I did not follow lint best practices here.
Walk Through
I assumed the following things while writing the code
The response from that route is a JSON containing a list of values and labels for each city. Something like this :
[{ value : "AM" , label : "Amsterdam" }, .... ]The only things you may need to read about for this example are :
If you have any questions, please comment my response, I will be happy to explain/add/modify