不允许空提交

来源:互联网 发布:大数据时代 宣传片 编辑:程序博客网 时间:2024/05/17 07:37
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<script language="javascript">
function confirmform1(){
if (!returnhasonechecked()) {
alert("请选择一个!");
return false;
}
return true;
}
function returnhasonechecked(){
var num=2;
var bb=false;
for(i=1;i<=num;i++){
if(document.all("checkbox"+i).checked==false){
}else bb=true;
}
return bb;
}
</script>

</head>

<body>
<form name="form1" method="post" action="index.jsp" onSubmit="return confirmform1()">
  <input type="checkbox" name="checkbox1" value="checkbox" id="checkbox1">
  11
  <input type="checkbox" name="checkbox2" value="checkbox" id="checkbox2">
  22

  <input type="submit" name="Submit" value="提交" id="Submit">
</form>

</body>
</html>