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
//test.php
<?php
require_once("config.php");
$db = connect();
$bikes = getSet($db,"select * from bikes order by bike_name",null);
$zories = getSet($db,"select distinct(zory) from members order by zory",null);
$countries = getSet($db,"select * from countries order by country_name",null);
?>
$(function() {
var jArray_countries = <?php echo json_encode($countries); ?>;
fill_select_by_json_set("country",jArray_countries,"country_id","country_name");
var jArray_zories = <?php echo json_encode($zories); ?>;
fill_select_by_json_set("zory", jArray_zories,null,"specialization");
var jArray_bikes = <?php echo json_encode($bikes); ?>;
fill_select_by_json_set("bike", jArray_bikes,"bike_id","bike_name");
});
function fill_select_by_json_set(ctl_name, json_set, json_id, json_txt){
if(json_set && ctl_name){
var combo_rows = "<option value='0'></option>";
for (var i = 0; i < json_set.length; i++)
{
if (json_id)
combo_rows += "<option value='" + json_set[i][json_id] + "'>" + json_set[i][json_txt] + "</option>";
else
combo_rows += "<option>" + json_set[i][json_txt] + "</option>";
}
$("[name="+ctl_name+"]").html(combo_rows);
$("[name="+ctl_name+"]").change();
}
}
<div class="container">
<div class='form-group'>
<label>Country :</label>
<select name="country" class='form-control'></select>
</div>
<div class='form-group'>
<label>zory :</label>
<select name="zory" class='form-control'></select>
</div>
<div class='form-group'>
<label>Bikes :</label>
<select name="bike" class='form-control'></select>
</div>
</div>
origin - http://www.pipiscrew.com/?p=1764 jsphp-get-set-to-combo-function