判断复选框被选中的个数,决定是否提交表单。
<script>
function checkIt()
{
var myobject = delForm.User_Oid;
var mynum = myobject.length;
var count=0;
if(mynum)
{
var flag=false;
for (i=0; i<mynum; i++)
{
if(myobject[i].checked)
{ count++;}
}
if(count==0)
{ document.getElementById('tips').innerHTML="请至少选择一个"; return false;}
if(count>0)
{
document.getElementById('tips').innerHTML="选择了一个以上";return true;
}
}
}
</script>
</head>
<body>
<form name="delForm" method="post" onsubmit="return checkIt()" action="aaa.asp">
<table width="100%" border="2" cellpadding="0" cellspacing="1" bordercolor="#CCCCCC" >
<tr bgcolor="#E7EFFF" bordercolor="#CCCCCC" height="20">
<td width="10%" align="center">
</td>
<td width="40%"> <div align="center">数据项</div></td>
</tr>
<tr name="defineFormat" bgcolor="ffffff">
<td height="20" >
<input name="User_Oid" type="checkbox" value="T2000000001">
</td>
<td height="20" > 01</td>
</tr>
<tr name="defineFormat" bgcolor="ffffff">
<td height="20" >
<input name="User_Oid" type="checkbox" value="T2000000002">
</td>
<td height="20" >02</td>
</tr>
<tr name="defineFormat" bgcolor="ffffff">
<td height="20" >
<input name="User_Oid" type="checkbox" value="T2000000003">
</td>
<td height="20" >03</td>
</tr>
</table>
<input type="submit">
</form>
<div id="tips" class=""></div>