Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > ช่วยดูcode JavaScript ทีครับมันมะยอมเช็คค่าให้อะเวลาผมใส่0หรือค่าว่างลงไปในจำนวนสินค้าอะ รบกวนทีนะครับขอบคุณ



 

ช่วยดูcode JavaScript ทีครับมันมะยอมเช็คค่าให้อะเวลาผมใส่0หรือค่าว่างลงไปในจำนวนสินค้าอะ รบกวนทีนะครับขอบคุณ

 



Topic : 086495



โพสกระทู้ ( 10 )
บทความ ( 0 )



สถานะออฟไลน์




Code (PHP)
<?php
ob_start();
// ใช้งานเช็ตชั่น เชื่อมต่อฐานข้อมูล เรียกใช้ฟังชั่น
session_start();
require("connect/connect.php");
require("connect/function.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>::: yookimji.com :::</title>
<link href="css/styles.css" rel="stylesheet" type="text/css">
<style type="text/css">
body {
	background-image: url(image/bgmain.gif);
}
</style>
</head>
<body topmargin="0" leftmargin="0" rightmargin="0" >
<div id="body" topmargin = "0">

<table width="800" border="0" align="center" cellpadding="0" cellspacing="1">
  <tr> 
 <td> 
 <table width="100%" border="0" background="image/wood_bg.jpg" cellpadding="0" cellspacing="0">
        <tr> 
		<td align="center">
		   <?php require_once('thead.php'); ?>
		<br>
            <?php require_once('menuhead.php'); ?>

<?php

//============ Check ว่ามีซ้ำแล้วหรือยัง
if($_GET["ProductID"] != "")
{
	for($i=0;$i<=count($_SESSION["strProductID"]);$i++)
	{
			if($_SESSION["strProductID"][$i] == $_GET["ProductID"])
			{
				$_SESSION["strQuanlity"][$i]++;
			header("location:$_SERVER[PHP_SELF]");
			exit();
			}
	}
}

//============ ถ้ามีการเลือกรายการสินค้าให้เก็บลง Session
if(trim($_GET["ProductID"]) != "")
{
	$_SESSION["strP"]=$_SESSION["strP"]+1;
	$_SESSION["strProductID"][$_SESSION[strP]]=$_GET["ProductID"];
	$_SESSION["strQuanlity"][$_SESSION[strP]]=1;
	session_write_close();
	header("location:$_SERVER[PHP_SELF]");
}	

//============ กรณีลบรายการสั่งซื้อ
if(trim($_GET["action"]) == "Del")
{
	$_SESSION["strProductID"][$_GET[P]]="";
	$_SESSION["strQuanlity"][$_GET[P]]="";
	session_write_close();
	header("location:$_SERVER[PHP_SELF]");
}	

//============ กรณีการแก้ไขรายการสั่งซื้อ
if(trim($_POST["action"]) == "Update")
{
for($i=0;$i<count($_POST["txtQua"]);$i++)
{	
	$strP=$_POST[txtP][$i];
	$strQ=$_POST["txtQua"][$i];
	if($strQ <= 0)
	{
	$strQ=1;
	}

	$_SESSION["strQuanlity"][$strP]=$strQ;

	$result=select("product","where 1=1 and ProductID='".$_SESSION["strProductID"][$strP]."'");
	if($result["Stock"] < $strQ)
	{
	$_SESSION["strQuanlity"][$strP]=$result["Stock"];
									echo"<script language='JavaScript'>";
									echo"alert('รหัสสินค้า [ $result[ProductCode] ] มีจำนวน Stock ไม่เพียงพอ');";
									echo"</script>";	
	}
	
	
}	
	session_write_close();
	//============ กระโดด Refresh ใหม่อีกรอบ
	header("location:$_SERVER[PHP_SELF]");
}	
?>			
          </td>
        </tr>
        <tr> 
          <td><table width="100%" border="0" background="image/wood_bg.jpg" cellpadding="0" cellspacing="0" >
              <tr> 
                <td width="23%" valign="top"> <?php require_once('menuleft.php'); ?> <br> </td>
                <td width="54%" valign="top"> 
                  <table width="100%" border="0" cellpadding="0" cellspacing="0" >
                  
                    <tr> 
                      <td width="417" height="310" valign="top" >
                        <form action="" method="post" name="frmCart" id="frmCart" onSubmit="return checkvalue();">
                          <table width="415"  align="center" border="0" bgcolor="Moccasin">
                            <br><tr> 
                              <td><table width="379" height="22" border="0" align="center" cellpadding="0" cellspacing="0" id="Table_01"bgcolor="Moccasin">
                                 <tr> 
                                    <td  width="379" background="image/wood2.png"><div align="center"><strong>รายการสั่งซื้อ 
                                        <input name="action" type="hidden" id="action" value="Update">
                                        </strong></div></td>
                                  </tr>
                                </table>
                                <strong> </strong></td>
                            </tr>
                            <tr> 
                              <td>&nbsp;</td>
                            </tr>
                            <tr> 
                              <td><table width="98%" height="21" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#666666">
                                  <tr bgcolor="Moccasin"> 
                                    <td ><div align="center">ลำดับ</div></td>
									<td><div align="center">ชื่อสินค้า</div></td>
									<td><div align="center">ราคา</div></td>
                                    <td><div align="center">จำนวน</div></td>
                                    <td><div align="center">รวม</div></td>
									 <td><div align="center">ลบสินค้า</div></td>
                                  </tr>
                                  <?php

						//============ ทำการแสดงรายการที่ได้เลือกว่ามีกี่รายการ

					$strNum=0;
					$strTotal=0;
					for($i=0;$i<=count($_SESSION["strProductID"]);$i++)
					{
					//============ เลือกว่ารายการสินค้าใดบ้าง
					$result=select("product","where 1=1 and ProductID='".$_SESSION["strProductID"]["$i"]."' ");
					if($result)
					{
					$strNum++;
					?>
                                  <tr bgcolor="#FFFFFF"> 
                                    <td width="9%"> <div align="center"> 
                                        <?=$strNum;?>
                                        </div></td>
                                    <td width="48%" align="center"> 
                                      <?=$result["ProductName"];?>
                                    </td>
                                    <td width="14%"> <div align="right"> 
                                        <?="".number_format($result["Price"], 2,'.',',');?>
                                      </div></td>
                                    
                                    <td width="13%"><div align="center"> 
                                        <input name="txtP[]" type="text" id="txtP[]" value="<?=$i;?>">
                                        <input name="txtQua[]" type="text" id="txtQua<?=$strNum;?>" style="width:30px;text-align:right" value="<?=$_SESSION["strQuanlity"]["$i"];?>" maxlength="4" onChange="checknum(this.value,'txtQua<?=$strNum;?>');">
                                      </div></td>
                                    <td width="16%"> <div align="right"> 
                                        <?="".number_format(($result["Price"])*$_SESSION["strQuanlity"]["$i"], 2,'.',',');?>
                                      </div></td>
									  <td width="9%"> <div align="center"> 
                                        <a href="javascript:if(confirm('ลบรายการสินค้า')==true){window.location='<?=$_SERVER['PHP_SELF'];?>?action=Del&P=<?=$i;?>';}"><img src="image/deleteC.gif" width="12" height="11" border="0"></a>
                                        </div></td>
                                  </tr>
                                  <?php
								  $strTotal=$strTotal+(($result["Price"])*$_SESSION["strQuanlity"]["$i"]);
											}
											}
											?>
                                        </table>
                                        <br> <table width="98%" height="21" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#666666">
                                          <tr bgcolor="#FFFFFF"> 
                                            <td><div align="right">จำนวน (รายการ)</div></td>
                                            <td> <div align="right"> 
                                                <?=$strNum;?>
                                              </div></td>
                                          </tr>
										   <tr bgcolor="#FFFFFF"> 
                                            <td><div align="right">ค่าจัดส่ง (บาท)</div></td>
                                            <td> <div align="right"> 
												<?php 
													if($strTotal < 1000 ){
														$strTotal+= 100;
														echo "100.00";
													}else{
														echo "ฟรี";
													}
												?>
                                              </div></td>
                                          </tr>
                                          <tr bgcolor="#FFFFFF"> 
                                            <td> <div align="right">ราคารวม (บาท)</div></td>
                                            <td width="16%"> <div align="right"> 
                                                <?="".number_format($strTotal, 2,'.',',');?>
                                                <input name="txtTotal" type="hidden" value="<?=$strTotal;?>">
                                              </div></td>
                                  </tr>
                                </table></td>
                            </tr>
                            <tr> 
                              <td width="378"><div align="center"><br>
                                  <?php
							if($strNum==0)
							{
							echo "<br><center><strong><font color=red>ไม่มีรายการสั่งซื้อ</font></strong></center><br><br>";
							}
							?>
								<p>หากสั่งยอดรวมต่ำกว่า 1000 บาท คิดด่าจัดส่ง 100บาท <BR> หากซื้อมากกว่า 1000 บาท ฟรีค่าจัดส่ง</p>
                                  <input name="BtnContinute" type="button" class="button" id="BtnContinute2" value="ซื้อสินค้าต่อ" onClick="window.location='product.php';">
                                  &nbsp; 
                                  <?php
								  if($strNum>0)
								  {?>
                                  <input name="BtnCalu" type="submit" class="button" id="BtnCalu" value="คำนวณเงินใหม่">
                                  &nbsp; 
                                  <input name="BtnPayment" type="button" class="button" id="BtnPayment" value="ยืนยัน" onClick="window.location='pay.php';">
                                  <?php }?>
                                  <br>
                                </div></td>
                            </tr>
                          </table>
                          <p class="style59">&nbsp;</p>
                        </form>
						<p class="style59">&nbsp;
						<script language="JavaScript">
						function checknum(value,fields)
						{
						if(!check_number(value))
						{
						eval("document.all."+fields+".value='1';");
						alert('กรอกจำนวนไม่ถูกต้อง');
						}
						}
						
						function check_number(ch){
							var len, digit;
							if(ch == " "){ 
								return false;
									 len=0;
								}else{
									 len = ch.length;
							}
							for(var i=0 ; i<len ; i++)
							{
								digit = ch.charat(i)
								if(digit >="0" && digit <="9"){
									;	
								}else{
									return false;					
								}		
							}		
							return true;
						}						
						</script></p>
                       
                        <p class="style59">&nbsp;</p>
                        <p class="style59">&nbsp;</p></td>
                    </tr>
                  </table></td>
                <td width="23%" valign="top"> <?php require_once('menuright.php'); ?> </td>
              </tr>
              <tr> 
                <td colspan="3" valign="top">
                  <?php require_once('down.php'); ?>
                </td>
              </tr>
            </table></td>
        </tr>
      </table></td>
  </tr>
</table>
<div style="clear:both"></div>
        </div>
</body>
</html>




Tag : PHP, JavaScript









ประวัติการแก้ไข
2012-11-10 18:45:17
2012-11-10 18:48:11
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-11-09 22:39:35 By : panbanjong View : 1164 Reply : 2
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Code มันเยอะครับ ลองไล่ดูดี ๆ ครับ คุณน่าจะแก้ปัญหาได้เองโดยไม่ยากครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-11-10 20:01:03 By : mr.win
 


 

No. 2



โพสกระทู้ ( 10 )
บทความ ( 0 )



สถานะออฟไลน์


ขอบคุณครับผม กำลังพยายามอยู่ มันต้องเจอทางออกฮ่าๆ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-11-10 21:35:23 By : panbanjong
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ช่วยดูcode JavaScript ทีครับมันมะยอมเช็คค่าให้อะเวลาผมใส่0หรือค่าว่างลงไปในจำนวนสินค้าอะ รบกวนทีนะครับขอบคุณ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 05
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่