|
 |
|
อยากทราบวิธีการใช้งาน Ajax Autocomplete ครับผมโหลดมาแล้วใช้งานไม่ได้ รบกวนดูให้ทีครับว่าผมทำผิดขั้นตอนไหน |
|
 |
|
|
 |
 |
|
หน้า FORM
<?php
session_start();
ob_start();
$db->connectdb(DB_NAME,DB_USERNAME,DB_PASSWORD);
?>
<script type="text/javascript" src="../bof/modules/employee/jquery.js"></script>
<script type='text/javascript' src='../bof/modules/employee/jquery.autocomplete.js'></script>
<link rel="stylesheet" type="text/css" href="../bof/modules/employee/jquery.autocomplete.css" />
<script type="text/javascript">
$().ready(function() {
$("#course").autocomplete("get_course_list.php", {
width: 260,
});
});
</script>
</head>
<body>
<h2 id="banner">Ajax Autocomplete Demo
- Jquery, PHP, Mysql</h1>
<div id="content">
<form autocomplete="off">
<p>
User ID
<label>:</label>
<input type="text" name="course" id="course" />
<!--input type="button" value="Get Value" /-->
</p>
<input type="submit" value="Submit" />
</form>
</div>
หน้า get_course_list.php
<?php
$db->connectdb(DB_NAME,DB_USERNAME,DB_PASSWORD);
$q = strtolower($_GET["q"]);
if (!$q) return;
$sql = "select EmpCode from tm_employee where EmpCode LIKE '%$q%'";
$res = $db->select_query($sql)or die($sql);
while($rec = $db->fetch($res)){
echo $rec['EmpCode']."\n";
}
?>
ดังภาพ

แต่ผมต้องการแก้ไขให้สามารถ Autocomplete ใน textbox อื่นด้วย
แบบนี้

พอมีแนวทางหรือการปรับแต่งไหมครับ
Tag : PHP, Ms SQL Server 2008, Ajax, jQuery

|
|
 |
 |
 |
 |
Date :
2012-02-02 22:21:37 |
By :
golderboy |
View :
1253 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองเรียกไฟล์ get_course_list.php มันมี error หรือเปล่าครับ
|
 |
 |
 |
 |
Date :
2012-02-02 23:27:43 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่มี error ครับ
อันนี้คือcode ที่ผมกำลังแก้อยู่ครับ
ส่งค่าไป
get_course_list.html?type=course", {
width: 260,
});
$("#user").autocomplete("employee-get_course_list.html?type=user", {
width: 260,
});
//ส่งค่าไป
รับค่ามา
if($type = "course"){
$sql = "select EmpCode from tm_employee where EmpCode LIKE '%$q%'";
$res = $db->select_query($sql)or die($sql);
while($rec = $db->fetch($res)){
echo $rec['EmpCode']."\n";
}
if($type = "user"){
$sql = "select EmpName from tm_employee where EmpName LIKE '%$q%'";
$res = $db->select_query($sql)or die($sql);
while($rec = $db->fetch($res)){
echo $rec['EmpName']."\n";
}
//หน้ารับค่า
พอลองทดสอบดู ไม่ขึ้นทั้งสองช่องเลยครับ
|
 |
 |
 |
 |
Date :
2012-02-02 23:33:08 |
By :
golderboy |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แก้ไขครับ
หน้าส่งค่า
<script type="text/javascript">
$().ready(function() {
$("#course").autocomplete("get_course_list.php?type=course", {
width: 260,
});
$("#user").autocomplete("get_course_list.php?type=user", {
width: 260,
});
});
</script>
|
 |
 |
 |
 |
Date :
2012-02-02 23:38:24 |
By :
golderboy |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|