如何在电子商务表格上要求最低数量?
我正在使用 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;}
关于javascript - 我如何在电子商务表格上要求最低数量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20591534/