xxxxxxxxxx
1
<div class="row">
2
<div class="col-12">
3
<select class="mdb-select md-form md-selected colorful-select dropdown-primary" searchable="Suche" name="oertlichkeit" onchange="fetch_select(this.value);" required>
4
<option></option>
5
<option>Alterssiedlung</option>
6
<option>Asylunterkunft</option>
7
<option>Brücke</option>
8
</select>
9
<label class="mdb-main-label">Örtlichkeit *</label>
10
</div>
11
</div>
12
13
<div class="row">
14
<div class="col-12">
15
<select class="mdb-select md-form md-selected colorful-select dropdown-primary" searchable="Suche" name="ort" id="ort" required>
16
<option></option>
17
</select>
18
<label class="mdb-main-label">Ort *</label>
19
</div>
20
</div>
21
22
23
<?php
24
//This is my dydropdown_data.php
25
if(isset($_POST['get_option']))
26
{
27
require'inc/db_connect.php';
28
29
$oertlichkeit = $_POST['get_option'];
30
31
$tabelle = "";
32
33
if($oertlichkeit == "Alterssiedlung")
34
{
35
$tabelle = "tbl_alterssiedlungen";
36
37
}elseif($oertlichkeit == "Asylunterkunft")
38
{
39
$tabelle = "tbl_asylunterkuenfte";
40
41
}elseif($oertlichkeit == "Brücke")
42
{
43
$tabelle = "tbl_bruecken";
44
45
}
46
$sql="SELECT * FROM $tabelle";
47
48
// Leere Option ermöglichen bei Auswahlfeld
49
50
foreach ($conn->query($sql) as $row)
51
{
52
echo "<option>".$row['Name']."</option>";
53
}
54
55
exit;
56
}
57
?>
1
1
xxxxxxxxxx
1
// Material Select Initialization
2
$(document).ready(function() {
3
$('.mdb-select').materialSelect();
4
});
5
6
function fetch_select(val)
7
{
8
$.ajax({
9
type: "POST",
10
url: 'dydropdown_data.php',
11
data: {
12
get_option:val
13
},
14
success: function (response) {
15
var html = "<option></option>"; //Variable html Fügt zusätzlich leeres <option> ein bei DropDown Feld
16
document.getElementById("ort").innerHTML=html + response;
17
}
18
});
19
}
Console errors: 0