|  |  | 
          
            | ถามเกี่ยวกับการใช้ฟังก์ชั่นเเจ้งเตือนหน่อยครับ ถ้าสมมติจำนวนในช่อง=0 ให้เเจ้งเตือนกรุณากรอกข้อมูล ซึ่งidตัวเเรกสามารถใช้ได้ปกติ 
 
 
 
 
 
 
 
 
 
 
  
 
 
 
 
 
 
 
 พอเลือกจำนวนอื่นที่มากกว่า0 ก้สามารถรถกดรับเข้าได้
 
 
 
 
 
 
 
 
  
 
 
 
 
 
 
 เเต่พอid ที่2 กดเลือกจำนวนที่มากกว่า0  มันเด้งฟังก์ชั่นเเจ้งเตือนว่ากรุณากรอกข้อมูล ในรูปจะเห็นว่าผมกรอกไป4ตัวเเต่ก็ยังเเจ้งเตือน
 
 
 
 
 
 
 
 
 
  
 
 
 
 
 
 
 อันนี้โค๊ดครับ
 Code (PHP)
 
 <?php session_start(); 
if(!isset($_SESSION['id']) || $_SESSION['id']==""){
  header("Location:login.php");  
  exit;      
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>index</title>
    <link rel="stylesheet" href="node_modules\bootstrap\dist\css\bootstrap.min.css">
</head>
<body>
<?php
	ini_set('display_errors', 1);
  error_reporting(~0);
  date_default_timezone_set('Asia/Bangkok');
  
  $strKeyword = null;
    if(isset($_POST["txtKeyword"]))//เซ็ตรับค่าช่องsearch
    {
        $strKeyword = $_POST["txtKeyword"];
    }
    if(isset($_GET["txtKeyword"]))//เซ็ตรับค่าช่องsearch
    {
        $strKeyword = $_GET["txtKeyword"];
    }
    
    
   $serverName = "localhost";//เชื่อมต่อฐานข้อมูล
   $userName = "root";
   $userPassword = "";
   $dbName = "crudsystem";
   $conn = mysqli_connect($serverName,$userName,$userPassword,$dbName);
   mysqli_query($conn, "SET CHARACTER SET UTF8");//เซ็ตเป็นเเบบUTF 8 ทำให้อ่านภาษาไทยได้
  
   $sql = "SELECT * FROM stock WHERE Part LIKE '%".$strKeyword."%' OR Dis LIKE '%".$strKeyword."%'  ";//รับค่าจากฐานข้อมูล เเละ ใช้คำสั่งในการค้นหา
   $query = mysqli_query($conn,$sql);
   $num_rows = mysqli_num_rows($query);
?>
<script type="text/javascript">  // อันนี้ฟังก์ชั่นสคริปครับ
function fncSubmit()
{
    if(document.getElementById('txtQty').value == 0)
    {
        alert('กรุณาใส่จำนวน');
        return false;
    }
}
</script>
<table class="table  table-striped table-bordered table-info">
  <thead>
</div>
      <th width=7% scope="col"><div align="center">No.</th>
      <th scope="col"><div align="center">Part</th>
      <th scope="col"><div align="center">Dis.</th>
      <th scope="col"><div align="center">Branch</th>
      <th scope="col"><div align="center">QTY.</th>
      <th width=5% scope="col"><div align="center">จำนวน</th>
      <th scope="col"><div align="center">รับเข้า</th>
      <th scope="col"><div align="center">เเก้ไข</th>
      <th scope="col"><div align="center">ลบ</th>
    </tr>
  </thead>
  <?php
  if(mysqli_num_rows($query) <1){
  ?>
  <tr>
    <td colspan="8"><div align="center">ไม่พบข้อมูล</div></td>
    
  </tr>
  <?php 
  }
  else
  {
    while($result=mysqli_fetch_array($query,MYSQLI_ASSOC))
    {//เเสดงข้อมูลทั้งหมดที่เราเลือกไว้
    ?>
          <tbody>
          <form action="save1.php?id=<?php echo $result["id"];?>"  method="post" name="form1" onSubmit="JavaScript:return fncSubmit();">
            <tr>
            <tr>
            <td><div align="center"><?php 
            
              $idso = $result["id"];
            echo $idso;
            
            ?></div></td>
            <td width=20%><?php echo $result["Part"];?></td>
            <td width=25%><?php echo $result["Dis"];?></td>
            <td width=10%><div align="center"><?php echo $result["Branch"];?></div></td>
            <td width=7%><div align="center"><?php echo $result["QTY"];?></td>
            <input type="hidden" name="QTY" value="<?php echo $result["QTY"];?>">
            <input type="hidden" name="nameuser" value="<?php echo $_SESSION['name']?>" >
            <input type="hidden" name="H_date" value="<?php echo date('d-m-Y H:i:s');?>" >
            <input type="hidden" name="HHPart" value="<?php echo $result["Part"];?>" >
            <input type="hidden" name="HHDis" value="<?php echo $result["Dis"];?>" >
            <input type="hidden" name="llid" value="<?php echo $result["id"];?>" >
            <td>
                <select id="txtQty" name="txtqty" <?php echo $i;?>> //ตัวช่องกรอกอยู่นี้ครับ
         
          <?php
          for($qty=0;$qty<=20;$qty++)
                {
                  ?>
                  <option value="<?php echo $qty;?>"><?php echo $qty;?></option>
                  <?php
                  }
                  */
          ?>    
        
          <?php
          $sql = "SELECT * FROM stock WHERE id='$idso'";
          $query_sql = mysqli_query($conn,$sql) or die($sql);
          $result = mysqli_fetch_array($query_sql);
          $num1 = $result['QTY'];
          for($qty=0;$qty<=100;$qty++)
                  {
                  ?>
                  <option value="<?php echo $qty;?>"><?php echo $qty;?></option>
                  <?php
                  }
                  ?> 
              </select>
  
                        <td width=7%><input type="submit" id="request" name="request" class="btn-info btn" value="รับเข้า"></td>
                        <td width=7%><div align="center"><button class="btn-danger btn"> 
                                         <a href="update1.php?id=<?php echo $result['id']; ?>" class="text-white" >
                                        เเก้ไข </a> </button> 
                                          <td width=7%><div align="center"><button class="btn-danger btn"> 
                                         <a href="delete.php?id=<?php echo $result['id']; ?>" class="text-white">
                                       ลบ </a> </button> 
                                       
                  
              
            
                  </td>
                </form>
          </tr>
        <?php
    }
}
?>
</table>
mysqli_close($conn);
?>
    <script src="node_modules\jquery\dist\jquery.min.js"></script>
    <script src="node_modules\bootstrap\dist\js\bootstrap.min.js"></script>
    <script src="node_modules\popper.js\dist\umd\popper.min.js"></script>
    
    
</body>
</html>
 อยากทราบว่าใส่ฟังก์ชั่นผิดตรงไหนหรือปล่าวครับ
 
 
 
 Tag : PHP, Apache, Appserv, XAMPP
 
 
 |  
            | 
 ประวัติการแก้ไข
 2019-04-25 09:57:58
 |  
            | 
              
                |  |  |  |  
                |  | 
                    
                      | Date :
                          2019-04-25 09:54:54 | By :
                          mostc007 | View :
                          704 | Reply :
                          1 |  |  |  
                |  |  |  |  |  
            |  |  
		            |  |