01.
<script>
02.
function
findcustomer(str)
03.
{
04.
if
(str.length == 0) {
05.
document.getElementById(
"customer_fname"
).innerHTML =
""
;
06.
return
;
07.
}
else
{
08.
var
xmlhttp =
new
XMLHttpRequest();
09.
xmlhttp.onreadystatechange =
function
() {
10.
if
(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
11.
document.getElementById(
"customer_fname"
).value = xmlhttp.responseText;
12.
var
qty= xmlhttp.responseText;
13.
}
14.
}
15.
xmlhttp.open(
"GET"
,
"find_customer.php?id="
+str, true);
16.
xmlhttp.send();
17.
}
18.
}
19.
function
filter() {
20.
var
keyword = document.getElementById(
"customer_fname"
).value;
21.
var
select = document.getElementById(
"customer_id"
);
22.
for
(
var
i = 0; i < select.length; i++) {
23.
var
txt = select.options[i].text;
24.
if
(txt.substring(0, keyword.length).toLowerCase() !== keyword.toLowerCase() && keyword.trim() !==
""
) {
25.
select.options[i].style.display =
'none'
;
26.
}
else
{
27.
select.options[i].style.display =
'list-item'
;
28.
}
29.
}
30.
}
31.
</script>
32.
33.
<div
class
=
"form-group"
>
34.
<label
for
=
"customer_id"
class
=
"col-sm-2 control-label"
>ชื่อลูกค้า</label>
35.
<div
class
=
"col-sm-2"
>
36.
<input type=
"text"
class
=
"form-control"
name=
"customer_fname"
id=
"customer_fname"
placeholder=
"กรองชื่อลูกค้า"
onkeyup=
"filter()"
>
37.
</div>
38.
<div
class
=
"col-sm-8"
>
39.
<select name=
"customer_id"
id=
"customer_id"
class
=
"form-control"
onchange=
"findcustomer_current(this.value)"
>
40.
<option value=
""
>
41.
--กรุณาเลือก--
42.
</option>
43.
<?php
44.
$sqld
=
" select * from tb_customer"
;
45.
if
(isset(
$_GET
[
'customer_id'
]))
46.
{
47.
$customer_id
=
$_GET
[
'customer_id'
];
48.
$sqld
.=
" where"
;
49.
$sqld
.=
" customer_id='$customer_id'"
;
50.
}
51.
$resultd
=
$cls_con
->select_base(
$sqld
);
52.
while
(
$rowd
=mysqli_fetch_array(
$resultd
))
53.
{
54.
$customer_id
=
$rowd
[
'customer_id'
];
55.
$customer_fname
=
$rowd
[
'customer_fname'
];
56.
?>
57.
<option value=
"<?=$customer_id;?>"
>
58.
<?=
$customer_fname
;?>
59.
</option>
60.
<?php } ?>
61.
</select>
62.
</div>
63.
</div>