-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultiple_select.php
56 lines (43 loc) · 1.04 KB
/
multiple_select.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
<?php
$conn=mysqli_connect("localhost","root","","aromafeeds");
if(!$conn){
die("Database not connected");
}
?>
<form action="">
Select State:
<select name="state" id="state" onchange="showCity(this.value)">
<option value="select" selected>Choose..</option>
<?php
$state="";
$sql="SELECT DISTINCT States FROM cities";
$result=mysqli_query($conn, $sql);
if(mysqli_num_rows($result)>0){
while($row=mysqli_fetch_assoc($result)){
echo "<option>". $row['States']. "</option>";
}
}
?>
</select>
Select City:
<select name="city" id="city">
<option value="selected" selected>Choose..</option>
</select>
</form>
<script>
function showCity(str) {
var xhttp;
if (str == "") {
document.getElementById("city").innerHTML = "";
return;
}
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("city").innerHTML = this.responseText;
}
};
xhttp.open("GET", "prepare_city.php?q="+str, true);
xhttp.send();
}
</script>