javascriptasp.netunobtrusive-javascript

Javascript validation for .net dropdownlistbox control?


I have 3 dropdownlistbox..

  1. country
  2. state
  3. cities

When I am selecting country name, as per its state name and city name change. In that if I am changing state name then city name is changed in dropdownlist box.

Using only Javascript not postback of .net control.

I have faced so much problem by making array of country, states and cities.

I thought if I have list of names of countries, states and cities than how can I maintain array of it?

So help me to get out of it, and give me good Javascript to get out from this problem?


Solution

  • Try this

    var countries = [
       {
           name:'USA',
           states:[
                {
                    name:'New York',
                    cities:['New York','Albany',...,'Some place']
                },
                {
                    name:'Florida',
                    cities:['Miami','Ft Loterdale']
                }
           ]
       },
       {
            name:'Canada' ...
       }
    ]