ชวยแก้ทีคับ javascript โค๊ดเช็คสินค้าในสต็อกคับ คือว่ามันไปเช็คเลขหลักแรกอย่าเดียว เช่น สินค้ามีอยู่ 12 ซื้อ1 ชิ้นได้ แต่พอซื้อ 2 ชิ้นกลับแจ้งเตือน ขออภัยคะท่านสั่งสินค้าเกินจำนวนที่ร้านเรามีคะ รบกวนช่วยทีคับ
alert qty ดูครับ
Date :
2013-07-23 07:52:39
By :
gaowteen
มีโค้ดเท่านี้หรอครับ ลองwrite ค่า Qty ออกมาดูว่าได้เท่าไหร่ครับ
ลองแปลงค่า Stock กับ Qty ให้เป็น int ก่อนเอามาเข้า if..else ก่อนครับ
Date :
2013-07-23 07:55:18
By :
hwang
นี่โค๊ดเต็มๆ คับ
<?php
@session_start();
if($_SESSION["Username"]=="")
{
header("location:index_customer.php");
exit();
}
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("casio");
?>
<script type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
<style type="text/css">
<!--
.style6 {font-family: Arial, Helvetica, sans-serif}
body,td,th {
font-size: 16px;
}
-->
</style>
</head>
<body onload="MM_preloadImages('images/cus2_03.jpg','images/cus2_04.jpg','images/cus2_05.jpg','images/cus2_06.jpg','images/member2_03.jpg')">
<table width="1030" border="0" align="center" bgcolor="#E2EDF3">
<tr>
<td width="1024" height="455" bgcolor="#E2EDF3"><img src="images/customer01.gif" width="1024" height="410" /><img src="images/cus_02.jpg" width="42" height="43" /><a href="index_customer.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image13','','images/cus2_03.jpg',1)"><img src="images/cus_03.jpg" name="Image13" width="154" height="43" border="0" id="Image13" /></a><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image14','','images/cus2_04.jpg',1)"><img src="images/cus_04.jpg" name="Image14" width="163" height="43" border="0" id="Image14" /></a><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image15','','images/cus2_05.jpg',1)"><img src="images/cus_05.jpg" name="Image15" width="238" height="43" border="0" id="Image15" /></a><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image16','','images/cus2_06.jpg',1)"><img src="images/cus_06.jpg" name="Image16" width="190" height="43" border="0" id="Image16" /></a><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image17','','images/cus2_07.jpg',0)"><img src="images/cus_07.jpg" name="Image17" width="191" height="43" border="0" id="Image17" /></a><img src="images/cus_08.jpg" width="46" height="43" /></td>
</tr>
<tr>
<script language="JavaScript">
var HttPRequest = false;
function doCallAjax(SID,PID,Qty,Stock) {
alert(Qty);
if(Stock<Qty) {
//alert(Qty);
alert(' ขออภัยคะท่านสั่งสินค้าเกินจำนวนที่ร้านเรามีคะ');return false;
}
else
{
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;
}
if(SID==""){
var url = 'shoping2.php';
var pmeters = "tPID=" + PID+
"&tQty=" + Qty;
//+"&tMode=" + Mode;
//alert("pmeter="+pmeters);
}
else{
var url = 'shoping2.php';
var pmeters = "tPID=" + PID+
"&tQty=" +Qty+
"&sess=" +SID;
//+"&tMode=" + Mode;
//alert("pmeter="+pmeters);
}
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;
}
}
}
function CheckOut()
{
window.location = 'shoping3.php';
}
</script>
<td width="1024" valign="top"><form id="form1" name="form1" method="post" action="shoping.php">
<table width="347" border="0" align="right">
<tr>
<td width="341" align="right">ค้นหาสินค้า
<input name="txtsearch" type="text" id="txtsearch" />
<input type="submit" name="Submit" value="ค้นหา" /></td>
</tr>
</table>
</form>
<p align="left">
<?php
$strMode = $_POST["tMode"];
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("casio");
$txtsearch=$_POST["txtsearch"];
?>
<? $strSQL = "SELECT * FROM product,catagory where product.CatID=catagory.CatID and(name like '%$txtsearch%' or CatName like '%$txtsearch%' or price like '%$txtsearch%') ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
</p>
<div align="center"><p align="left"><form action="" method="post" name="form1" id="form1" >
<br />
<table width="950" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="800" height="270" align="center" valign="top"><div align="center">
<p>
<?php
$strMode = $_POST["tMode"];
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("casio");
$txtsearch=$_POST["txtsearch"];
?>
<? $strSQL = "SELECT * FROM product,catagory where product.CatID=catagory.CatID and(name like '%$txtsearch%' or CatName like '%$txtsearch%' or price like '%$txtsearch%') ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<?
//$strSQL = "SELECT * FROM game ORDER BY IDG ASC";
//$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
//$strSQL = "SELECT * FROM game where CatID like '%$catid%' ORDER BY IDG ASC";
//$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
echo"<table border=\"0\" cellspacing=\"1\" cellpadding=\"1\"><tr>";
$intRows = 0;
while($objResult = mysql_fetch_array($objQuery))
{
//$sum=$objResult["price"]+$objResult["price"];
$pict=explode("\\",$objResult["picture"]);
$cnt=count($pict);
$stock=$objResult["Stock"];
$name=$objResult["name"];
$price=$objResult["price"];
$CatName=$objResult["CatName"];
$test=1;
$intRows++;
echo "<td>";
?>
</p>
<div align="center"><img src="<?="../admin/picture/".$pict[$cnt-1];?>" width="100" height="100" border="0" /></div>
</div>
<?
if($stock>=$test){
?>
<center>
<?=$objResult["name"]; ?>
<br />
<?= $objResult["CatName"];?>
<br />
<?= $objResult["price"];?>
บาท<br />
<?= $objResult["Stock"];?>
<br />
<a href="Detail_cus.php?temp=<?=$objResult["PID"];?>"> <input name="button" type="button" value="ดูรายละเอียดสินค้า"/></a>
<br />
<label>ระบุจำนวนสินค้า
<input type="text" id="txt<?=$intRows;?>" style="width:20px" maxlength="20" />
</label>
ชิ้น
<br />
<input type="button" onClick="JavaScript:doCallAjax('','<?=$objResult["PID"];?>', document.getElementById('txt<?=$intRows;?>').value, '<?= $objResult["Stock"];?>');" value="สั่งซื้อสินค้า"/>
<br />
<?
}else
{
echo"<center>$name</center>";
echo"<center>$CatName</center>";
echo"<center>$price บาท</center>";
echo "<center><font color=\"#FF0000\">สินค้าหมด!!</font></center>";
}
?>
</center>
<?
echo"</td> ";
if(($intRows)%4==0)
{
echo"</tr>";
}
else
{
echo "<td>";
}
}
echo"</tr></table>";
?>
<?
mysql_close($objConnect);
?> </td>
</tr>
</table>
</form>
<form id="form2" name="form2" method="post" action="shoping3.php">
<span id="mySpan"></span>
</form> <p></p>
</td>
</tr>
<tr>
<td><img src="images/customer07.jpg" width="1024" height="116" /></td>
</tr>
</table>
</body>
</html>
ประวัติการแก้ไข 2013-07-23 12:55:28 2013-07-23 13:29:48
Date :
2013-07-23 12:54:27
By :
kaw0676078
Load balance : Server 00