01.
<?php
02.
session_start();
03.
include
(
"connect_db.php"
);
04.
connect_db();
05.
?>
08.
<head>
09.
<meta http-equiv=
"Content-Type"
content=
"text/html; charset=utf-8"
/>
10.
<title>Untitled Document</title>
11.
12.
<script language =
"JavaScript"
>
13.
14.
15.
function
ListSubOffice(SelectValue)
16.
{
17.
form1.s_office.length = 0
18.
19.
20.
var
myOption =
new
Option(
''
,
''
)
21.
form1.s_office.options[form1.s_office.length]= myOption
22.
23.
<?
24.
$intRows
= 0;
25.
$strSQL
=
"SELECT * FROM s_office ORDER BY s_office_id ASC "
;
26.
$objQuery
= mysql_query(
$strSQL
)
or
die
(
"Error Query ["
.
$strSQL
.
"]"
);
27.
$intRows
= 0;
28.
while
(
$objResult
= mysql_fetch_array(
$objQuery
))
29.
{
30.
$intRows
++;
31.
?>
32.
x = <?=
$intRows
;?>;
33.
mySubList =
new
Array();
34.
35.
strGroup = <?=
$objResult
[
"office_id"
];?>;
36.
strValue =
"<?=$objResult["
s_office_id
"];?>"
;
37.
strItem =
"<?=$objResult["
s_office_n
"];?>"
;
38.
mySubList[x,0] = strItem;
39.
mySubList[x,1] = strGroup;
40.
mySubList[x,2] = strValue;
41.
if
(mySubList[x,1] == SelectValue){
42.
var
myOption =
new
Option(mySubList[x,0], mySubList[x,2])
43.
form1.s_office.options[form1.s_office.length]= myOption
44.
}
45.
<?
46.
}
47.
?>
48.
}
49.
50.
51.
</script>
52.
53.
</head>
54.
55.
<body>
56.
57.
<form name=
"form1"
action=
"test.php"
method=
"post"
>
58.
Office
59.
<select id=
"office"
name=
"office"
onChange =
"ListSubOffice(this.value)"
>
60.
<option selected value=
"0"
>กรุณาเลือกหน่วยงาน</option>
61.
<?
62.
$strSQL
=
"SELECT * FROM office ORDER BY office_id ASC "
;
63.
$objQuery
= mysql_query(
$strSQL
)
or
die
(
"Error Query ["
.
$strSQL
.
"]"
);
64.
while
(
$objResult
= mysql_fetch_array(
$objQuery
))
65.
{
66.
?>
67.
<option value=
"<?=$objResult["
office_id
"];?>"
><?=
$objResult
[
"office_n"
];?></option>
68.
<?
69.
}
70.
?>
71.
</select>
72.
73.
Sub Office
74.
<select id=
"s_office"
name=
"s_office"
style=
"width:120px"
></select>
75.
76.
</form>
77.
78.
</body>
79.
</html>