|
|
|
ช่วยดูโค้ดให้หน่อยได้ไม๊คะว่าผิดตรงไหนหรอ จึงส่งค่า Ajax ไม่ไปนะคะ |
|
|
|
|
|
|
|
Go to : Ajax Auto Fill Textbox (PHP+MySQL and ASP+Access)https://www.thaicreate.com/tutorial/ajax-auto-fill-textbox.html
จากหน้านี้คะ
Code (PHP)
//AutoFill
var HttPRequest = false;
function doCallAjax(fProductName,fProductID) {
//alert(fProductName+fProductID);
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 = 'AjaxGetFill.php';
var pmeters = "tProductName=" + encodeURI( document.getElementById(fProductName).value);
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(fProductName).innerHTML = "..";
//}
if(HttPRequest.readyState == 4) // Return Request
{
var myProduct = HttPRequest.responseText;
if(myProduct != "")
{
var myArr = myProduct.split("|");
document.getElementById(fProductID).value = myArr[0];
//document.getElementById(fPrice).value = myArr[1];
}
}
}
}
function CreateNewRow()
{
var intLine = parseInt(document.frm_request.hdnMaxLine.value);
intLine++;
var theTable = document.getElementById("tbExp");
var newRow = theTable.insertRow(theTable.rows.length)
newRow.id = newRow.uniqueID
var newCell
//*** Column 1 ***//
newCell = newRow.insertCell(0);
newCell.id = newCell.uniqueID;
newCell.setAttribute("className", "css-name");
newCell.innerHTML = "<center><SELECT NAME=\"txtProductName1"+intLine+"\" ID=\"txtProductName1"+intLine+"\" OnChange=\"JavaScript:doCallAjax('txtProductName1"+intLine+"','txtProductID1'"+intLine+");\"></SELECT></center>";
--------------------------------- เมื่อเลือกข้อมูลในในฟิลด์นี้ จะ Fill ข้อมูล ใส่ลงใน ฟิดล์นี้ txtProductID1"+intLine+ นะคะ --------------------------------------
//*** Create Option ***//
CreateSelectOption("txtProductName1"+intLine,"productTiles"+intLine,intLine)
//*** Column 2 ***// ---------------------------------ตรงนี้ข้อมูลที่ต้อง Fill Auto จากการเลือกข้อมูลใน Column 1 ---------
newCell = newRow.insertCell(1);
newCell.id = newCell.uniqueID;
newCell.setAttribute("className", "css-name");
newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"20\" NAME=\"txtProductID1"+intLine+"\" ID=\"txtProductID1"+intLine+"\" VALUE=\"\"></center>";
}
ไฟล์ AjaxGetFill.php
/*** By Weerachai Nukitram ***/
/*** http://www.ThaiCreate.Com ***/
include("../../includes/config.php");
include(INCLUDES_PATH."connectDB_access.php");
$strProduct = trim($_POST["tProductName"]);
$strSQL = "SELECT * FROM tbl_spt_productTiles WHERE productName_en = '".$strProduct."' ";
$result_dataUser = odbc_exec($link,$strSQL) or die ("Error Query [".$strSQL."]");
//$objResult = mysql_fetch_array($objQuery);
while($itemUser = odbc_fetch_array($result_dataUser))
{
echo $itemUser["material_code"]."|".$itemUser["Price1_perBaseUnit"];
}
mysql_close($objConnect);
ช่วยด้วยคะ
ขอบคุณมากกกกๆๆๆๆ
Tag : PHP, Ms Access
|
|
|
|
|
|
Date :
2011-05-02 12:50:08 |
By :
unzeen |
View :
744 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ได้แล้วคะ ปิด กระทุ้เรย
|
|
|
|
|
Date :
2011-05-02 13:43:44 |
By :
unzeen |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|