Array vullen met gegevens uit database
Code (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
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
$(document).ready(function(){
var Bosch = [
{display: "", value: "0" },
{display: "GC7000i-14", value: "GC7000i-14" },
{display: "GC7000i-24", value: "GC7000i-24" },
{display: "GC7000i-24 C", value: "GC7000i-24 C" },
{display: "GC7000i-28 C", value: "GC7000i-28 C" }];
var Buderus = [
{display: "", value: "0" },
{display: "GB072-24", value: "GB072-24" },
{display: "GB072-24K", value: "GB072-24" },
{display: "GB172-24", value: "GB172-24" },
{display: "GB172-24K", value: "GB172-24K" }];
var Junkers = [
{display: "", value: "0" },
{display: "ZBR 70-3", value: "ZBR 70-3" },
{display: "ZBR 100-3", value: "ZBR 100-3" },
{display: "ZSB 14-4C", value: "ZSB 14-4C" },
{display: "ZSB 24-4C", value: "ZSB 24-4C" }];
$("#Brand_selection").change(function() {
var parent = $(this).val();
switch(parent){
case 'Bosch':
list(Bosch);
break;
case 'Buderus':
list(Buderus);
break;
case 'Junkers':
list(Junkers);
break;
default: //default child option is blank
$("#type_selection").html('');
break;
}
});
function list(array_list)
{
$("#type_selection").html("");
$(array_list).each(function (i) {
$("#type_selection").append('<option value="'+array_list[i].value+'">'+array_list[i].display+'</option>');
});
}
});
var Bosch = [
{display: "", value: "0" },
{display: "GC7000i-14", value: "GC7000i-14" },
{display: "GC7000i-24", value: "GC7000i-24" },
{display: "GC7000i-24 C", value: "GC7000i-24 C" },
{display: "GC7000i-28 C", value: "GC7000i-28 C" }];
var Buderus = [
{display: "", value: "0" },
{display: "GB072-24", value: "GB072-24" },
{display: "GB072-24K", value: "GB072-24" },
{display: "GB172-24", value: "GB172-24" },
{display: "GB172-24K", value: "GB172-24K" }];
var Junkers = [
{display: "", value: "0" },
{display: "ZBR 70-3", value: "ZBR 70-3" },
{display: "ZBR 100-3", value: "ZBR 100-3" },
{display: "ZSB 14-4C", value: "ZSB 14-4C" },
{display: "ZSB 24-4C", value: "ZSB 24-4C" }];
$("#Brand_selection").change(function() {
var parent = $(this).val();
switch(parent){
case 'Bosch':
list(Bosch);
break;
case 'Buderus':
list(Buderus);
break;
case 'Junkers':
list(Junkers);
break;
default: //default child option is blank
$("#type_selection").html('');
break;
}
});
function list(array_list)
{
$("#type_selection").html("");
$(array_list).each(function (i) {
$("#type_selection").append('<option value="'+array_list[i].value+'">'+array_list[i].display+'</option>');
});
}
});
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<tr>
<td height="30px"></td>
<td>Merk</td>
<td>
<select name="Brand_selection" id="Brand_selection">
<option value="0">-- Please Select --</option>
<option value="Bosch">Bosch</option>
<option value="Buderus">Buderus</option>
<option value="Junkers">Junkers</option>
</select>
</td>
<td>Type</td>
<td>
<select name="type_selection" id="type_selection">
</select>
</td>
<td></td>
</tr>
<td height="30px"></td>
<td>Merk</td>
<td>
<select name="Brand_selection" id="Brand_selection">
<option value="0">-- Please Select --</option>
<option value="Bosch">Bosch</option>
<option value="Buderus">Buderus</option>
<option value="Junkers">Junkers</option>
</select>
</td>
<td>Type</td>
<td>
<select name="type_selection" id="type_selection">
</select>
</td>
<td></td>
</tr>
Edit:
Quote-tags omgezet in code-tags. Gelieve dit in het vervolg te gebruiken voor code en scripts in het forum.
Alvast bedankt.
Alvast bedankt.
Gewijzigd op 28/08/2018 09:19:27 door - Ariën -
http://adoptive.esy.es/dynamic_select/
De JavaScript code staat in de broncode van de pagina.
Link naar origineel staat op pagina.
Een vergelijkbaar onderwerp hier (vlak onder uw eigen topic) :
https://www.phphulp.nl/php/forum/topic/dropdown-vraag-na-het-vullen-met-sql-gegevens/102342/
Ik raad inderdaad aan om dit met AJAX op te halen via een PHP-script waarin de data in JSON-formaat staat.
het zijn deze array's die gevuld zouden moeten worden met gegevens uit de database.
Quote:
var Bosch = [
{display: "", value: "0" },
{display: "GC7000i-14", value: "GC7000i-14" },
{display: "GC7000i-24", value: "GC7000i-24" },
{display: "GC7000i-24 C", value: "GC7000i-24 C" },
{display: "GC7000i-28 C", value: "GC7000i-28 C" }];
var Buderus = [
{display: "", value: "0" },
{display: "GB072-24", value: "GB072-24" },
{display: "GB072-24K", value: "GB072-24" },
{display: "GB172-24", value: "GB172-24" },
{display: "GB172-24K", value: "GB172-24K" }];
var Junkers = [
{display: "", value: "0" },
{display: "ZBR 70-3", value: "ZBR 70-3" },
{display: "ZBR 100-3", value: "ZBR 100-3" },
{display: "ZSB 14-4C", value: "ZSB 14-4C" },
{display: "ZSB 24-4C", value: "ZSB 24-4C" }];
{display: "", value: "0" },
{display: "GC7000i-14", value: "GC7000i-14" },
{display: "GC7000i-24", value: "GC7000i-24" },
{display: "GC7000i-24 C", value: "GC7000i-24 C" },
{display: "GC7000i-28 C", value: "GC7000i-28 C" }];
var Buderus = [
{display: "", value: "0" },
{display: "GB072-24", value: "GB072-24" },
{display: "GB072-24K", value: "GB072-24" },
{display: "GB172-24", value: "GB172-24" },
{display: "GB172-24K", value: "GB172-24K" }];
var Junkers = [
{display: "", value: "0" },
{display: "ZBR 70-3", value: "ZBR 70-3" },
{display: "ZBR 100-3", value: "ZBR 100-3" },
{display: "ZSB 14-4C", value: "ZSB 14-4C" },
{display: "ZSB 24-4C", value: "ZSB 24-4C" }];
Ik had gedacht om een tabel aan te maken met 2 kolommen. Een met het merk en een met het type.
Gewijzigd op 28/08/2018 09:39:36 door Wesley Van Kerckvoorde
Quote:
Kan ik daar eventueel hulp bij krijgen?
Nou en of :
https://lmgtfy.com/?q=teach+me+ajax
https://lmgtfy.com/?q=teach+me+json
http://lmgtfy.com/?q=the+concept+of+learning
Gewijzigd op 28/08/2018 11:06:20 door Adoptive Solution