|
 |
|
ปัญหาเรื่อง Ajax Auto Fill Textbox ในการแสดงหลายTextFile |
|
 |
|
|
 |
 |
|
จากความรู้เรื่อง ajax-auto-fill-textbox
https://www.thaicreate.com/tutorial/ajax-auto-fill-textbox.html
ผมได้ทำกาารแก้ไขเพิ่มเล็กน้อย เพื่อให้มันแสดงได้หลายTextFile
แต่มันไม่สามารถทำงานได้เลยสงสัยครับว่าต้องแก้ไขอื่นใดอีกหรือมั้ย ครับ
มันสามารถดึงมาได้ครับ จากเดิม 3 ช่อง ต้องการแสดงให้เป็น 5 ช่อง ครับ
Code (PHP)
AjaxAutoFill.php
<script language="JavaScript">
var HttPRequest = false;
function doCallAjax(fProductID,fProductName,fPrice) {
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 = "tProductID=" + encodeURI( document.getElementById(fProductID).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(fProductName).value = myArr[0];
document.getElementById(fPrice).value = myArr[1];
}
}
}
}
</script>
<form name="frmMain">
<table width="70%" border="1">
<tr>
<th width="84">Product ID </th>
<th width="185">Product Name </th>
<th width="99">Price</th>
<th width="99"> </th>
<th width="99"> </th>
</tr>
<tr>
<th>
<div align="center">
<input type="text" name="txtProductID1" id="txtProductID1" OnChange="JavaScript:doCallAjax('txtProductID1','txtProductName1','txtPrice1','textfield','textfield2');">
</div></th>
<th><input type="text" name="txtProductName1" id="txtProductName1" size="30"></th>
<th><input type="text" name="txtPrice1" id="txtPrice1" size="10"></th>
<th><input type="text" name="textfield" id="textfield"></th>
<th><input type="text" name="textfield2" id="textfield2"></th>
</label></th>
</tr>
<tr>
<th>
<div align="center">
AjaxGetFill.php
Code (PHP)
<?php
/*** By Weerachai Nukitram ***/
/*** http://www.ThaiCreate.Com ***/
$strProduct = trim($_POST["tProductID"]);
$objConnect = mysql_connect("localhost","library","compaq") or die("Error Connect to Database");
$objDB = mysql_select_db("library");
$strSQL = "SELECT * FROM book WHERE book_isbn = '".$strProduct."' ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$objResult = mysql_fetch_array($objQuery);
if($objResult)
{
echo $objResult["book_name"]."|".$objResult["book_page"]."|".$objResult["book_type"]."|".$objResult["book_state"];
}
mysql_close($objConnect);
?>
Tag : PHP, MySQL, JavaScript, Ajax

|
|
 |
 |
 |
 |
Date :
2012-02-21 14:20:59 |
By :
numprick |
View :
1566 |
Reply :
5 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
if($objResult)
{
echo $objResult["book_name"]."|".$objResult["book_page"]."|".$objResult["book_type"]."|".$objResult["book_state"];
}
เพิ่มให้ครบจาก 3 เป็น 5 ไม่น่ายากครับ
|
 |
 |
 |
 |
Date :
2012-02-21 15:55:21 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมลองเพิ่มแล้วครับ
เดิม
Code (PHP)
if($objResult)
{
echo $objResult["ProductName"]."|".$objResult["Price"];
}
ของใหม่
Code (PHP)
if($objResult)
{
echo $objResult["book_name"]."|".$objResult["book_state"]."|".$objResult["book_page"]."|".$objResult["book_type"];
}
แต่มันก็ยังคงแสดงออกมาเพียง 3 ช่องครับ สลับค่าตัวแปรที่แสดงผลออก
จากช่องที่3 ให้มาช่องที่ 4 แล้ว ก็ยังไม่มาครับ
|
 |
 |
 |
 |
Date :
2012-02-21 16:12:20 |
By :
numprick |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แก้ไขตรงนี้ครับ
Code (JavaScript)
if(HttPRequest.readyState == 4) // Return Request
{
var myProduct = HttPRequest.responseText;
if(myProduct != "")
{
var myArr = myProduct.split("|");
document.getElementById(fProductName).value = myArr[0];
document.getElementById(fPrice).value = myArr[1];
}
}
|
 |
 |
 |
 |
Date :
2012-02-22 06:14:43 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พี่ครับผมสงสัยครับ
ผมจะเอา AjaxAutoFill คู่กับ Ajax Check Username
https://www.thaicreate.com/tutorial/ajax-auto-fill-textbox.html
https://www.thaicreate.com/tutorial/ajax-check-username.html
แต่มันเป็น OnChange ในการทำงานทั้งคู่
ไม่รู้ว่าสามารถแก้ไข ยังไงได้บ้างหรอครับพี่่
เป็นของ ajax-auto-fill-textbox
OnChange="JavaScript:doCallAjax2('txtUsername','book_name','book_number_number','book_coppy','textfield2');"
เป็นของ ajax-check-username
OnChange="JavaScript:doCallAjax();"
Code (PHP)
<input type="text" name="txtUsername" id="txtUsername" OnKeyPress="return chkNumber(this)" OnChange="JavaScript:doCallAjax2('txtUsername','book_name','book_number_number','book_coppy','textfield2');" OnChange="JavaScript:doCallAjax();">
|
 |
 |
 |
 |
Date :
2012-02-23 15:42:41 |
By :
numprick |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ต้องการทำหน้าขายสินค้าแบบไม่ออนไลน์ ขั้นแรกใช้ Ajax Auto Fill Textbox ดึงข้อมูลสินค้ามาแสดงใน text box พอกดปุ่ม submit ให้ส่งค่า txtProductID1 ที่เรากรอกเข้าไปมาที่หน้าเดิม แล้วเอา txtProductID1 ที่รับเข้ามา มาค้นหาในฐานข้อมูลแล้วแสดงข้อมูลออกมาในอีก table เพื่อทำการใส่ จำนวนที่ต้องการขาย และคำนวณราคา
ปัญหาคือ
1.พอเราใส่ปุ่ม submit เข้าไป Ajax Auto Fill Textbox ไม่สามารถดึงข้อมูลมาโชว์ได้
2. ถ้าจะส่งค่า txtProductID1 ที่กรอกเข้าไปมาที่หน้าเดิมต้องทำไง

|
 |
 |
 |
 |
Date :
2012-03-22 00:09:36 |
By :
mai |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|