ปัญหารบกวนช่วยแนะนำเรื่องการ update Amount จาก textfield หน่อยค่ะ
AjaxPHPDeleteRecord1.php
<?php
/*** gg***/
?>
<html>
<head>
<title>ThaiCreate.Com Ajax Tutorial</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<script language="JavaScript">
var HttPRequest = false;
function doCallAjax(Mode,ID) {
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 = 'AjaxPHPDeleteRecord2.php';
var pmeters = "tMode=" + Mode +
"&tID=" + ID ;
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('LIST','');">
<form name="frmMain" method="post" >
<span id="mySpan"></span>
</form>
</body>
</html>
AjaxPHPDeleteRecord2.php
<?php
session_start();
if($_SESSION['UserID'] == "")
{
echo "Please Login!";
exit();
}
$strMode = $_POST["tMode"];
$strID = $_POST["tID"];
$objConnect = mysql_connect("localhost","root","13510047") or die("Error Connect to Database");
$objDB = mysql_select_db("project");
mysql_query("SET character_set_results=utf8");
mysql_query("SET character_set_client=utf8");
mysql_query("SET character_set_connection=utf8");
if($strMode == "DELETE")
{
$strSQL = "DELETE FROM temporary ";
$strSQL .="WHERE TemporaryID = '".$strID."' ";
$objQuery = mysql_query($strSQL);
}
if($strMode == "UPDATE")
{
$strSQL = "UPDATE temporary SET TAmount = '".?????."' ";
$strSQL .="WHERE TemporaryID ='".$strID."' ";
$objQuery = mysql_query($strSQL);
}
$strSQL = "SELECT TAmount,temporary.TemporaryID,ornament.OrnamentName, products.ProductID,products.Height,products.Width,products.Price,products.Depth,roof.RoofName,window.Name,porch.PorchName,door.DoorName,color.ColorName FROM temporary,products,roof,color,structure,porch,door,window,ornament WHERE products.ProductID=temporary.ProductID and products.RoofID=roof.RoofID and products.PorchID=porch.PorchID and products.DoorID=door.DoorID and products.PorchID=porch.PorchID and products.WindowID=window.WindowID and
structure.ColorID=color.ColorID and
products.StructureID=structure.StructureID and temporary.OrnamentID=ornament.OrnamentID and UserID = '".$_SESSION['UserID']."' and StatusID<=2";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<style type="text/css">
<!--
.style3 {color: #FFFFCC}
-->
</style>
<table width="605" height="85" border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#993333">
<tr bgcolor="<?=$bg?>">
<th height="43" colspan="6" bordercolor="#FFFFFF"><img src="img/line.png" width="650" height="43" /></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
if($bg == "#503927") { //ส่วนของการ สลับสี
$bg = "#815c3f";
} else {
$bg = "#503927";
}
?>
<tr bgcolor="<?=$bg?>">
<td width="105" height="70" bordercolor="#FFFFFF" bgcolor="<?=$bg?>"><div align="center" class="style3"><?=$objResult["ProductID"];?>
</div></td>
<td width="246" height="70" bordercolor="#FFFFFF" bgcolor="<?=$bg?>"><span class="style3">บ้าน<?=$objResult["ColorName"];?>
หลังคา<?=$objResult["RoofName"];?>
<?=$objResult["DoorName"];?>
<?=$objResult["Name"];?>
<?=$objResult["PorchName"];?>
[อุปกรณ์เสริม
<?=$objResult["OrnamentName"];?>
]</span></td>
<td width="68" height="70" align="center" valign="middle" bordercolor="#FFFFFF" bgcolor="<?=$bg?>"><div align="center" class="style3">
<label>
<input name="txtamount" type="text" id="txtamount" value="<?=$objResult["TAmount"];?>" size="2" maxlength="2" style="text-align: center;" />
</label>
</div></td>
<td width="105" height="70" bordercolor="#FFFFFF" bgcolor="<?=$bg?>"><div align="center" class="style3">
<?=$objResult["Price"];?>
</div></td>
<td width="70" height="70" align="center" valign="middle" bgcolor="<?=$bg?>"><img src="img/button_ok.png" style="cursor:hand" width="44" height="43" onclick="JavaScript:doCallAjax('UPDATE','<?=$objResult["TemporaryID"];?>');>
<map name="Map" id="Map">
<area shape="rect" coords="24,0,25,1" href="#" />
</map></td>
<td width="56" height="70" align="center" valign="middle" bgcolor="<?=$bg?>"><img src="img/delete1.png" style="cursor:hand" width="44" height="43" onclick="JavaScript:doCallAjax('DELETE','<?=$objResult["TemporaryID"];?>');" /></td>
</tr>
<?
}
?>
</table></form>
<?
mysql_close($objConnect);
?>
จากตัวอย่างด้านบนจะเห็นว่า AjaxPHPDeleteRecord1.php จะมี docallajax ไว้แยก mode ระหว่าง update กับ delete ค่ะ
ส่วนปัญหาคือต้องการอัพเดทค่าใน txtamount ใน if($strMode == "UPDATE") ของหน้า AjaxPHPDeleteRecord2.php ต้องทำยังไงค่ะ
รบกวนด้วยนะคะ ขอบคุณค่ะTag : PHP, JavaScript
Date :
2012-03-03 00:58:50
By :
willky
View :
990
Reply :
2
ลองแบบนี้ + "&tAmode=" + encodeURI( document.getElementById("txtamount").value );
ไปหน้าจะเป็นสีขาวค่ะ เหมือน txtamount อยู่ AjaxPHPDeleteRecord2.php อยู่แล้ว พอใส่ ใน AjaxPHPDeleteRecord1.php มันหา txtfield ตัวนั้นไม่เจออ่ะค่ะ รบกวนอีกทีนะคะ
Date :
2012-03-03 15:25:01
By :
willky
Load balance : Server 03