表单提交,JS代码不进行验证?
什么都不填点击提交,JS代码就是不验证啊,实在找不出哪有问题,请各位帮忙,谢谢。<%@ page language="java" pageEncoding="UTF-8"%>
<%
Object object = session.getAttribute("storekeeper");
if(object == null){
response.sendRedirect("../index.jsp");
}
%>
<%@include file="skinclude.jsp"%>
<html>
<head>
<title>增加店内商品</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css">
<!--
#Layer99 {
position:absolute;
width:703px;
height:32px;
z-index:1;
left: 330px;
top: 130px;
}
#Layer7 {
position:absolute;
width:624px;
height:452px;
z-index:5;
left: 350px;
top: 170px;
}
-->
</style>
<script type="text/javascript">
function checkProduct(){
if(document.addProduct.pro_name.value=""){
window.alert("商品名不能为空!");
document.addProduct.pro_name.focus();
return false;
}
if(document.addProduct.pro_producter.value=""){
window.alert("生产商不能为空!");
document.addProduct.pro_producter.focus();
return false;
}
if(document.addProduct.pro_price.value=""){
window.alert("销售价格不能为空!");
document.addProduct.pro_price.focus();
return false;
}
if(document.addProduct.pro_inventory.value=""){
window.alert("进货数量不能为空");
document.addProduct.pro_inventory.focus();
return false;
}
}
</script>
</head>
<%
String nsID = request.getParameter("nsID");
String nsName = new String(request.getParameter("nsName").getBytes("ISO-8859-1"),"UTF-8");
%>
<body>
<div id="Layer99">
<TABLE height=28 cellSpacing=3 cellPadding=0 width=776 align=center
border=0>
<TBODY>
<TR vAlign=bottom>
<TD> <A class=nav href="skindex.jsp">店主首页</A>
<FONT class=nav> > </FONT><A class=nav href="mynetstoreShow.jsp">我的网店列表</A>
<FONT class=nav> > </FONT><A class=nav href="javascript: history.back()"><%=nsName %></A>
<FONT class=nav> > </FONT><A class=nav href="javascript: location.reload()">增加商品</A></TD>
</TR>
</TBODY>
</TABLE>
</div>
<div id="Layer7" align="center">
<h2>增加商品(为了您的利益,请详细填写)</h2>
<form action="insertProduct.jsp?nsID=<%=nsID %>" name="addProduct" method="post">
<table align="center">
<tr><td>商品名称:</td><td><input type="text" name="pro_name"/></td></tr>
<tr><td>生产商:</td><td><input type="text" name="pro_producter"/></td></tr>
<tr><td>销售价格:</td><td> <input type="text" name="pro_price"/>元</td></tr>
<tr><td>进货数量:</td><td><input type="text" name="pro_inventory"/></td></tr>
<tr><td>是否上架:</td><td><select name="pro_onsale"><option value="1" selected="selected">上架销售</option>
<option value="0">下架待销</option>
</select>
</td></tr>
<tr><td>商品描述:</td><td><textarea rows="5" cols="15" name="pro_descn"></textarea></td></tr>
<tr><td colspan="2"><input type="submit" value="增加" onclick="return checkProduct();"/></td></tr>
</table>
</form>
</div>
</body>
</html>