开发者

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?


Try this

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


Why not this instead:

data: { 
  "United States" : {
    "California" : ["San Francisco","San Jose","Watsonville"],
    "Alaska" : ["Anchorage","Juneau"]
  },
  "Canada" : {
    "Alberta" : ["Calgary","another town"]
  }
}

This makes it territory neutral, not needing names like "state", "city", "province", etc. Iterate through the object by using

for(var key in data) { var country = data[key]; var state = data[key][territory] }

or use any number of object traversing methods.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜