![](/img/trans.png)
[英]How can I implement increase or decrease quantity till countInStock of my my e-commerce project with the below code?
[英]How Can I require a Minimum Quantity on an e-commerce Form?
如何在電子商務表格上要求最低數量?
我正在使用Mal的購物車表格,並且有一個價格優惠,但我想要求我的客戶最少擁有15個單位。
我嘗試將其添加到Serif WebPlus X6的現有javascript驗證函數中),它不起作用。
if('qty1'>=15) {return true;} else{ alert("Please enter Minimum Order of 15.") return false;}
這是完整的代碼:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Home</title>
<meta name="Generator" content="Serif WebPlus X6 (14.0.0.020)">
<meta name="viewport" content="width=960">
<script type="text/javascript">
function validate_ys-12x18-1c2s( form )
{
//Custom Validation Steps
if( ltrim(rtrim(form.elements['qty1'].value,' '),' ')=="" ) { alert("Please enter some text"); form.elements['qty1'].focus(); return false; }
if( isNaN( parseInt( form.elements['qty1'].value ) ) ) { alert("Please enter a number"); form.elements['qty1'].focus(); return false; }
if('qty1'>=15) {return true;} else{ alert("Please enter Minimum Order of 15.") return false;}
//Custom Validation for element
return true;
}
</script>
<style type="text/css">
body{margin:0;padding:0;}
.Button1,.Button1:link,.Button1:visited{background-image:url('wpimages/wp5325eb44_06.png');background-position:0px 0px;text-decoration:none;display:inline-block;background-color:transparent;border:none 0px;padding:0;}
.Button1:focus{outline-style:none;}
.Button1:hover{background-position:0px -45px;}
.Button1 span,.Button1:link span,.Button1:visited span{color:#ffffff;font-family:"Futura LtCn BT",sans-serif;font-weight:normal;text-decoration:none;text-align:center;text-transform:none;font-style:normal;left:9px;top:5px;width:127px;height:35px;font-size:27px;display:block;position:absolute;cursor:pointer;}
.Button1:hover span{color:#000000;left:18px;width:110px;}
.Button1:active span{color:#000000;left:18px;width:110px;}
</style>
</head>
<body text="#000000" style="background:#ffffff; height:1000px;">
<div style="background-color:transparent;margin-left:auto;margin-right:auto;position:relative;width:960px;height:1000px;">
<form id="ys-12x18-1c2s" onsubmit="return validate_ys-12x18-1c2s(this)" action="http://12.aitsafe.com/cf/addmulti.cfm" method="post" target="_self" style="margin:0;position:absolute;left:16px;top:13px;width:240px;height:125px;">
<input type="hidden" name="currency" value="">
<input type="hidden" name="product1[]" value="Yard Signs 12"x18" -1 Color-2 Side">
<input type="hidden" name="scode1" value="YdSgn-12x18-1c-2s">
<input type="hidden" name="price1" value="104.25">
<input type="hidden" name="discountpr1" value="24,6.99:25,4.99:50,3.09:50,2.29:100,2.09:250,1.99:500,1.89:9001,1.79">
<input type="hidden" name="return" value="www.MYDOMAIN.com/index.html">
<input type="hidden" name="lg" value="0">
<input type="hidden" name="userid" value="MYNUMBER">
<img src="wpimages/wpe73c68aa_06.png" border="0" width="60" height="20" title="" alt="QUANTITY " style="position:absolute;left:72px;top:25px;">
<input type="text" name="qty1" value="15" style="position:absolute; left:147px; top:25px; width:50px;">
<div style="position:absolute;left:62px;top:58px;width:145px;height:45px;"><button type="submit" id="btn_311" class="Button1" style="width:145px;height:45px;"><span>ADD TO CART</span></button></div>
</form>
<script type="text/javascript" src="wpscripts/jsValidation.js"></script>
</div>
</body>
</html>
您正在將字符串與數字15進行比較,而不是標記為“ qty1”的字段中的值。 在您上方的行中查看條件檢查。 您可能需要這樣的東西:
if( parseInt( form.elements['qty1'].value ) >=15) {return true;}
else{ alert("Please enter Minimum Order of 15."); return false;}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.