forked from priyanka2907/Country-State-City-Using-Ajax
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcountry.php
119 lines (84 loc) · 3.99 KB
/
country.php
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title> Country City State Demo</title>
<script src="jquery.min.js"></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
window.load=$( document ).ready(function() {
$.ajax({
type:'POST',
url:'countryAjaxData.php',
success:function(html){
$('#country').html(html);
}
});
});
$( document ).ready(function() {
$('#country').on('change',function(){//change function on country to display all state
var countryID = $(this).val();
if(countryID){
$.ajax({
type:'POST',
url:'ajaxData.php',
data:'country_id='+countryID,
success:function(html){
$('#state').html(html);
$('#city').html('<option value="">Select state first</option>');
}
});
}else{
$('#state').html('<option value="">Select country first</option>');
$('#city').html('<option value="">Select state first</option>');
}
});
$('#state').on('change',function(){//change state to display all city
var stateID = $(this).val();
if(stateID){
$.ajax({
type:'POST',
url:'ajaxData.php',
data:'state_id='+stateID,
success:function(html){
$('#city').html(html);
}
});
}else{
$('#city').html('<option value="">Select state first</option>');
}
});
});
</script>
</head>
<p id="profile1" style="color:red;margin-left:700px;margin-top:100px"><b>Country State City Examples</b></p><br>
<div class="row">
<div class="col-md-1 col-sm-12" id="lable1"></div>
<div class="col-md-1 col-sm-12" id="lable1"><id="lable1">Country</div>
<div class="col-md-2">
<select name="country" id="country"
data-live-search="true" class="chosen selectpicker form-control" required>
<option value="">Select Country</option>
</select>
</div>
<div class="col-md-1 col-sm-12" id="lable1"><id="lable1">State</div>
<div class="col-md-2">
<select class="selectpicker form-control" name="state" id="state" autofocus="autofocus" required>
<option value="">Select an Option</option>
</select>
</div>
<div class="col-md-1 col-sm-12" id="lable1"><id="lable1">City</div>
<div class="col-md-2">
<select class="selectpicker form-control" name="city" id="city" standard title="Select an Option" autofocus="autofocus" required>
<option value="">Select an Option</option>
</select></div>
</div>
</br>
</div>
</div>
<!--start 6 row-->