country city state js

Solutions on MaxInterview for country city state js by the best coders in the world

showing results for - "country city state js"
Davide
03 Jan 2017
1<!doctype html>
2<html>
3<head>
4<meta charset="utf-8">
5<title>Untitled Document</title>
6<script>
7var stateObject = {
8"India": {
9"Delhi": ["new Delhi", "North Delhi"],
10"Kerala": ["Thiruvananthapuram", "Palakkad"],
11"Goa": ["North Goa", "South Goa"],
12},
13"Australia": {
14"South Australia": ["Dunstan", "Mitchell"],
15"Victoria": ["Altona", "Euroa"]
16},
17"Canada": {
18"Alberta": ["Acadia", "Bighorn"],
19"Columbia": ["Washington", ""]
20},
21}
22window.onload = function () {
23var countySel = document.getElementById("countySel"),
24stateSel = document.getElementById("stateSel"),
25districtSel = document.getElementById("districtSel");
26for (var country in stateObject) {
27countySel.options[countySel.options.length] = new Option(country, country);
28}
29countySel.onchange = function () {
30stateSel.length = 1; // remove all options bar first
31districtSel.length = 1; // remove all options bar first
32if (this.selectedIndex < 1) return; // done
33for (var state in stateObject[this.value]) {
34stateSel.options[stateSel.options.length] = new Option(state, state);
35}
36}
37countySel.onchange(); // reset in case page is reloaded
38stateSel.onchange = function () {
39districtSel.length = 1; // remove all options bar first
40if (this.selectedIndex < 1) return; // done
41var district = stateObject[countySel.value][this.value];
42for (var i = 0; i < district.length; i++) {
43districtSel.options[districtSel.options.length] = new Option(district[i], district[i]);
44}
45}
46}
47</script>
48</head>
49<body>
50<form name="myform" id="myForm">
51Select Country: <select name="state" id="countySel" size="1">
52<option value="" selected="selected">Select Country</option>
53</select>
54<br>
55<br>
56Select State: <select name="countrya" id="stateSel" size="1">
57<option value="" selected="selected">Please select Country first</option>
58</select>
59<br>
60<br>
61Select District: <select name="district" id="districtSel" size="1">
62<option value="" selected="selected">Please select State first</option>
63</select><br>
64<input type="submit">
65</form>
66</body>
67</html>
68