标签:javascript
//表单验证
function check() {
productName = document.getElementById("productName");
if (productName.value == null || productName.value.length == 0) {
alert("请填写商品名称!!");
productName.value = "";
productName.focus();
return false;
}
explanation = document.getElementById("explanation");
if (explanation.value == null || explanation.value.length == 0) {
alert("请填写分享描述!!");
explanation.value = "";
explanation.focus();
return false;
}
picFile = document.getElementById("picFile");
if (picFile.value == null || picFile.value.length == 0) {
alert("请上传商品图片!!");
picFile.value = "";
picFile.focus();
return false;
}
classify1 = document.getElementById("classify1");
if (classify1.value == null || classify1.value.length == 0) {
alert("请选择一级分类!!");
classify1.value = "";
classify1.focus();
return false;
}
classify2 = document.getElementById("classify2");
if (classify2.value == null || classify2.value.length == 0) {
alert("请选择二级分类!!");
classify2.value = "";
classify2.focus();
return false;
}
sku = document.getElementById("sku");
if (sku.value == null || sku.value.length == 0) {
alert("请填写商品属性!!");
sku.value = "";
sku.focus();
return false;
}
marketPrice = document.getElementById("marketPrice");
if (marketPrice.value == null || marketPrice.value.length == 0) {
alert("请填写商品市场价格!!");
marketPrice.value = "";
marketPrice.focus();
return false;
}
var re = /^\d+(?=\.{0,1}\d+$|$)/
var pattern = /^\d+$/;
if (!pattern.test(marketPrice.value)&&!re.test(marketPrice.value)) {
alert("商品市场价格必须为数字!!");
//skuid.focus();
return false;
}
groupPrice = document.getElementById("groupPrice");
if (groupPrice.value == null || groupPrice.value.length == 0) {
alert("请填写商品团购价格!!");
groupPrice.value = "";
groupPrice.focus();
return false;
}
var pattern = /^\d+$/;
if (!pattern.test(groupPrice.value)&&!re.test(groupPrice.value)) {
alert("商品团购价格必须为数字!!");
//skuid.focus();
return false;
}
productCode = document.getElementById("productCode");
if (productCode.value == null || productCode.value.length == 0) {
alert("请填写商品货号!!");
productCode.value = "";
productCode.focus();
return false;
}
startTime = document.getElementById("startTime");
if (startTime.value == null || startTime.value.length == 0) {
alert("请填写开始时间!!");
startTime.value = "";
startTime.focus();
return false;
}
endTime = document.getElementById("endTime");
if (endTime.value == null || endTime.value.length == 0) {
alert("请填写结束时间!!");
endTime.value = "";
endTime.focus();
return false;
}
sum = document.getElementById("sum");
if (sum.value == null || sum.value.length == 0) {
alert("请填写商品数量!!");
sum.value = "";
sum.focus();
return false;
}
var pattern = /^\d+$/;
if (!pattern.test(sum.value)) {
alert("商品数量必须为数字!!");
//skuid.focus();
return false;
}
startSum = document.getElementById("startSum");
if (startSum.value == null || startSum.value.length == 0) {
alert("请填写初始抢购数!!");
startSum.value = "";
startSum.focus();
return false;
}
var pattern = /^\d+$/;
if (!pattern.test(startSum.value)) {
alert("初始抢购数必须为数字!!");
//skuid.focus();
return false;
}
everyIdLimit = document.getElementById("everyIdLimit");
value = everyIdLimit.value;
if (document.getElementById("radio").checked && value <= 0) {
alert("限购数必须大于0!!");
everyIdLimit.value = "";
everyIdLimit.focus();
return false;
}
var pattern = /^\d+$/;
if (document.getElementById("radio").checked && !pattern.test(startSum.value)) {
alert("限购数必须为数字!!");
//skuid.focus();
return false;
}
/* shipMethod = document.getElementsByName("shipMethod");
alert(shipMethod);
if (shipMethod == null || shipMethod.length == 0) {
alert("请选择配送方式!!");
shipMethod= "";
shipMethod.focus();
return false;
} */
if (!document.getElementById("shipMethod").checked) {
alert("请选择配送方式!!");
shipMethod.focus();
return false;
}
if (!document.getElementById("paymentType").checked) {
alert("请选择支付方式!!");
paymentType.focus();
return false;
}
/* paymentType = document.getElementById("paymentType");
if (paymentType.value == null || paymentType.value.length == 0) {
alert("请选择支付方式!!");
paymentType.value = "";
paymentType.focus();
return false;
} */
notice = document.getElementById("notice");
if (notice.value == null || notice.value.length == 0) {
alert("请填写团购须知!!");
notice.value = "";
notice.focus();
return false;
}
productInfo = document.getElementById("productInfo");
if (productInfo.value == null || productInfo.value.length == 0) {
alert("请填写商品详情!!");
productInfo.value = "";
productInfo.focus();
return false;
}
document.form.submit();
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:javascript
原文地址:http://blog.csdn.net/wuzhiweiwuzhiwei/article/details/47725685