Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
80
rated 0 times [  81] [ 1]  / answers: 1 / hits: 67776  / 11 Years ago, mon, july 1, 2013, 12:00:00

I am trying to accomplish dropdowns using JSON. I want 3 dropdowns. First populate the country dropdown (eg: usa, uk etc.,). Now, when the user select USA then states dropdown needs to be populated by using jQuery .change(). Again when user select the state they need to be presented with cities dropdowns.



How can I achieve this? As my JSON file is slightly big I have added it here and tried to populate countries dropdown but unable to generate states and cities drop down...



http://jsfiddle.net/vCFv6/



$.each(myJson.country, function (index, value) {
$(#country).append('<option value='+value.id+'>'+value.name+'</option>');});


The above code helps me populate just the countries but not others like states and cities. Any help is much appreciated.



Thanks in advance.


More From » jquery

 Answers
9

Exactly like others said, you have to handle the onchange event of country & state select inputs & apply your logic. I have fiddled here for getting states dynamically on selecting a country, you might be able to code the rest yourself - Fiddle



You may also see this
Populating Dropdown Based On Other Dropdown Value


[#77282] Saturday, June 29, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
naya

Total Points: 60
Total Questions: 87
Total Answers: 87

Location: Guam
Member since Fri, Jun 18, 2021
3 Years ago
;