-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaddress.js
89 lines (82 loc) · 2.2 KB
/
address.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
var countries = [];
var states = [];
function pairForCountries(geonameObj)
{
var result = Array();
result[0] = geonameObj["name"];
result[1] = geonameObj["geonameId"]
return result;
}
function pairForCitiesOrStates(geonameObj)
{
var result = Array();
result[0] = geonameObj["name"];
result[1] = geonameObj["geonameId"]
return result;
}
function listOfCountries(elemId)
{
countries = [];
var countryGeonameIds = [6255146, 6255152, 6255147, 6255148, 6255149, 6255151, 6255150]
var count = 0;
for(x in countryGeonameIds)
{
count++;
$.getJSON("http://www.geonames.org/childrenJSON?geonameId="+countryGeonameIds[x], function(data){
count--;
$.merge(countries,data["geonames"]);
if (count==0)
allCountries(elemId);
});
}
}
function listOfStatesOrCities(elem, elemId)
{
states = [];
$.getJSON("http://www.geonames.org/childrenJSON?geonameId="+$("#"+elem.id+" option:selected").attr('data-role'), function(data){
states = data["geonames"];
statesOrCities(elemId);
});
}
function allCountries(elemId)
{
countries = (countries.map(pairForCountries)).sort();
var src = document.getElementById(elemId);
src.options.length = 0;
var count = countries.length;
if(count)
src.options[src.options.length] = new Option('Select','')
else
src.options[src.options.length] = new Option('No Data Available','')
for(var i=0;i<count;i++)
{
var tmp = countries[i][0];
var index = src.options.length;
src.options[index] = new Option(tmp, tmp)
$($("#"+elemId+" > option")[index]).attr('data-role', countries[i][1]);
}
}
function statesOrCities(elemId)
{
states = (states.map(pairForCitiesOrStates)).sort();
var src = document.getElementById(elemId);
src.options.length = 0;
var count = states.length;
if(count)
{
src.options[src.options.length] = new Option('Select','')
src.disabled = false;
}
else
{
src.options[src.options.length] = new Option('No Data Available','')
src.disabled = true;
}
for(var i=0;i<count;i++)
{
var tmp = states[i][0];
var index = src.options.length;
src.options[index] = new Option(tmp,tmp);
$($("#"+elemId+" > option")[index]).attr('data-role', states[i][1]);
}
}