Javascript validation for .net dropdownlistbox control?
I have 3 dropdownlistbox..
- country
- state
- 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.
精彩评论