我想要做的是檢查文本框輸入數量是否大於數據庫中的可用數量。應該顯示ADD
按鈕的警報onclick()
。檢查輸入數量是否大於數據庫中的可用數量
ADD
按鈕
<button type="button" name="btnSave" id="btnSave" onclick="submitdata(); resetform(); checkQty();">ADD</button>
checkQty()
功能
function checkQty() {
//Grab current forms input field values.
var txtQuantity = document.getElementById("txtQuantity").value;
var listItemName = document.getElementById("listItemName").value;
//Connect to database and verify Quantity Ordered isnt greater than Quantity In Stock.
$.ajax({
type: "POST",
url: "/pms/includes/functions/qty_check.php",
data: 'listItemName=' + listItemName + '&txtQuantity=' + txtQuantity,
}).responseText;
}
qty_check.php
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
//Start the Session
if(!isset($_SESSION))
{
session_start();
}
include_once("../../config.php");
require __DIR__."../../dbutil.php";
if(!empty($_POST['txtQuantity'])){$qty = $_POST['txtQuantity'];}
if(!empty($_POST['listItemName'])){$item = $_POST['listItemName'];}
$results = mysqli_query($connection, "SELECT * FROM purchase_items WHERE item_id= ".$_GET['listItemName']"");
$row = mysqli_fetch_assoc($results);
{
$tb_qty=$row["avail_qty"];
}
if($tb_qty < $qty){ ?>
<script type="text/javascript">
alert("Quantity exceeds the stock limit");
</script>
<?php
}
?>
我嘗試了很多,但我無法解決這個問題。感謝任何幫助。
究竟是什麼錯誤?是你的JavaScript功能嗎? – GraveyardQueen
@GraveyardQueen它不顯示任何錯誤,但警報不按預期顯示。 – EKBG
你從查詢中得到結果嗎? – GraveyardQueen