|
|
|
ขอตัวอย่าง เมื่อมีการกรอกรหัสพนักงานแล้วให้แสดงชื่ออัตโตมัติเลย |
|
|
|
|
|
|
|
อยากได้ตัวอย่างด้วยคนนะใครก็ได้ช่วยชี้แนะ
|
|
|
|
|
Date :
2009-11-17 10:10:41 |
By :
***** |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
search_ajax.php
Code (PHP)
<html>
<head>
<title>drinker</title>
</head>
<script language="JavaScript">
var HttPRequest = false;
function doCallAjax(Search) {
HttPRequest = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
HttPRequest = new XMLHttpRequest();
if (HttPRequest.overrideMimeType) {
HttPRequest.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
HttPRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
HttPRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!HttPRequest) {
alert('Cannot create XMLHTTP instance');
return false;
}
var url = 'search_db_ajax.php';
var pmeters = 'mySearch='+Search;
HttPRequest.open('POST',url,true);
HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
HttPRequest.setRequestHeader("Content-length", pmeters.length);
HttPRequest.setRequestHeader("Connection", "close");
HttPRequest.send(pmeters);
HttPRequest.onreadystatechange = function()
{
if(HttPRequest.readyState == 3) // Loading Request
{
document.getElementById("mySpan").innerHTML = "Now is Loading...";
}
if(HttPRequest.readyState == 4) // Return Request
{
document.getElementById("mySpan").innerHTML = HttPRequest.responseText;
}
}
}
</script>
<body Onload="JavaScript:doCallAjax('');">
<h1>My Customer</h1>
<form name="frmMain">
Search <input type="text" name="txtSearch" id="txtSearch" onKeyUp="JavaScript:doCallAjax(document.getElementById('txtSearch').value);">
<br><br>
<span id="mySpan"></span>
</form>
</body>
</html>
search_db_ajax.php
Code (PHP)
<?php
$strSearch = $_POST["mySearch"];
$objCon = mysql_connect("localhost","","") or die("Error Connect Database");
$objDB = mysql_select_db("artdrinker");
$strSQL = "SELECT * FROM customer WHERE CustID LIKE '%".$strSearch."%' ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<table width="600" border="1">
<tr> <th width="91"> <div align="center">ID</div></th>
<th width="98"> <div align="center">Name</div></th> </tr>
<?
while($objRst = mysql_fetch_array($objQuery)){
?>
<tr> <td><div align="center"><?=$objRst["CustID"];?></div></td>
<td><?=$objRst["CustName"];?></td> </tr>
<? } ?>
</table>
อะครับ อย่างที่ใจนึก
|
|
|
|
|
Date :
2009-11-18 13:53:11 |
By :
Sek-Artdrinker |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|