 |
|
รบกวนผู้ชำนาญเรื่อง Ajax หน่อยค่ะ
พอดีอยากทราบว่ากรณีที่เราคิวรี่แล้วได้ข้อมูลมากกว่า 1 ค่านะคะ ต้องการที่จะให้มันโชว์ข้อความว่าProductIDนี้มีชื่อมากกว่า1ชื่อตามข้อความด้านล่างนะคะ และตรงช่อง textbox ตัวที่ 2 จะต้องไม่โชว์ค่านะคะ
document.getElementById("chklabel").innerHTML="Grouping Code นี้ชื่อสินค้ามากว่า 1 ชื่อค่ะ";
โค้ดหน้า test.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<title>test</title>
<style type="text/css">
<!--
.style1 {font-family: "Times New Roman", Times, serif}
-->
</style>
</head>
<script language="JavaScript">
var HttPRequest = false;
function doCallAjax(fCodeGroup,fCode) {
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 = "code_group=" + encodeURI( document.getElementById(fCodeGroup).value);
HttPRequest.open('POST',url,true);
HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=windows-874");
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 myCodegroup = HttPRequest.responseText;
if(myCodegroup != "")
{
var myArr = myCodegroup.split("|");
document.getElementById(fCode).value = myArr[0];
document.getElementById("chklabel").innerHTML="Grouping Code นี้ชื่อสินค้าแล้วค่ะ";
}else{
document.getElementById("chklabel").innerHTML="Grouping Codeนี้ยังไม่มีชื่อสินค้าค่ะ";
return false;
}
}
}
}
</script>
<body>
<h1>Auto Fill Form</h1>
<form name="frmMain">
<table width="191" border="1">
<tr>
<th width="181">Group_Code </th>
</tr>
<tr>
<th>
<input type="text" name="code_group" id="code_group" onChange="JavaScript:doCallAjax('code_group','code');"></th>
</tr>
<tr>
<th id="chklabel" > </th>
</tr>
<tr>
<th>
<input type="text" name="code" id="code" ></th>
</tr>
</table>
</form>
</body>
</html>
โค้ดหน้าcheck.php
<?php
$strProduct = $_POST["code_group"];
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("Product");
$strSQL = "SELECT distinct(code_group),old_code FROM Product WHERE code_group = '".$strProduct."' ";
$objQuery = mysql_query($strSQL) or die (mysql_error());
while($objResult = mysql_fetch_array($objQuery)){
if($objResult)
{
echo $objResult['old_code'];
}
}
mysql_close($objConnect);
?>
Tag : - - - -
|
|
 |
 |
 |
 |
Date :
2010-01-30 19:52:31 |
By :
กิ๊ก |
View :
1043 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |