如何在页面还没提交以前判断选择了几个多选项?

tokilcoom 2006-08-21 04:26:09
一个多选项,最多只能选10项,如何能在页面还没提交以前判断是否超过10项?
超过10项就不允许提交,少于10项才允许提交。
...全文
197 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
tokilcoom 2006-08-22
  • 打赏
  • 举报
回复
这样不对吗?
<!-- #include file="conn.asp"-->
<%
function CheckForm(){
var cb=document.getElementsByName("v");
var c=0;
for (i=0;i<cb.length;i++){
if (cb[i].checked){
if(++c>10){
alert("超过10项,不允许提交!");
return false;
}
}
}
}

%>
document.write ("<html><head><title>投票</title>");
document.write ("<link href='css.css' rel='stylesheet' type='text/css'>");
document.write ("<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>");
document.write ("</head><body>");
document.write ("<form method='post' onSubmit='return CheckForm();' action='votes.asp'><table border='1' cellpadding='5' cellspacing='0' bordercolordark='#f7f7f7' bordercolorlight='#cccccc' class='inputt'>");
liangjianshi 2006-08-22
  • 打赏
  • 举报
回复
应该就是leohuang(LEO)所说的,
你在仔细检查检查。
tokilcoom 2006-08-22
  • 打赏
  • 举报
回复
leohuang(LEO)
谢谢 但是总是提示语法错误
leohuang 2006-08-22
  • 打赏
  • 举报
回复

function CheckForm(){
var cb=document.getElementsByName("v");
var c=0;
for (i=0;i<cb.length;i++){
if (cb[i].checked){
if(++c>10){
alert("超过10项,不允许提交!");
return false;
}
}
}
}
把上面的代码放最上面,
<form method='post' action='votes.asp'>
改成<form method='post' action='votes.asp' onsubmit='return CheckForm();'>
xzr2004 2006-08-22
  • 打赏
  • 举报
回复
document.write 是在客户端执行,asp是在服务端执行,而你输出中有asp脚本,肯定不正常了,
把document.write -> Response.Write

document.write ("<img src='<%=rs1("img")%>'><br><input type='radio' name='v' value='<%=rs1("id")%>'><%=rs1("cont")%><br>");

有很多地方要改了
Response.Write ("<img src='"&rs1("img")&"'><br><input type='radio' name='v' value='"&rs1("id")&"'>"&rs1("cont")&"<br>");

tokilcoom 2006-08-22
  • 打赏
  • 举报
回复
小弟刚刚学习,希望各位大虾详细指教,根据上面各位的指导,我做了一下,但是总是不能正常,没办法,还请各位看看源码

document.write ("<form method='post' action='votes.asp'><table border='1' cellpadding='5' cellspacing='0' bordercolordark='#f7f7f7' bordercolorlight='#cccccc' class='inputt'>");
<%
on error resume next
dim id,rs,chk
ip=Request.ServerVariables("REMOTE_ADDR")
id=request.querystring("id")
if id<>"" then
set rs=server.createobject("adodb.recordset")
rs.open "select title,types,brstr from V_title where id=cint('"&id&"')",conn,1,1
if not rs.eof then
chk=rs("types")
%>
document.write ("<tr><td bgcolor='#f7f7f7' height='30'><font color='#ff0000'><%=rs("title")%></font></td></tr><tr><td><table border='0' width='100%' class='inputt'>");

<%
dim rs1,i
set rs1=server.createobject("adodb.recordset")
rs1.open "select * from V_vote where lid=cint('"&id&"')",conn,1,1
if not rs1.eof then
do while not rs1.eof
if i<>0 then
if (i mod rs("brstr"))=0 then
%>
document.write ("<tr>");

<%end if
end if
%>
document.write ("<td>");
<%
select case rs("types")
case "1" '单选
%>
document.write ("<img src='<%=rs1("img")%>'><br><input type='radio' name='v' value='<%=rs1("id")%>'><%=rs1("cont")%><br>");
<%
case "2" '多选
%>
document.write ("<img src='<%=rs1("img")%>'><br><input type='checkbox' name='v' value='<%=rs1("id")%>'><%=rs1("cont")%><br>");
<%
end select

%>
document.write ("</td>");

<%
i=i+1
rs1.movenext
loop
end if
rs1.close
%>
<%
end if
rs.close
end if
%>
document.write ("</table></td></tr>");
document.write ("<tr><td bgcolor='#f7f7f7' height='30' align='center'><input type='hidden' name='ip' value='<%=ip%>'><input type='hidden' name='idd' value='<%=id%>'><input type='submit' name='submit' value='投票' class='inputt'>  <input type='button' name='button1' value='查看' class='inputt' onclick=window.open('view.asp?id=<%=id%>','vie','scrollbars=yes,resizable=yes,width=550,height=250');><input type='hidden' name='id' value='<%=id%>'><input type='hidden' name='chk' value='<%=chk%>'></td></tr></table></form></body></html>");
tokilcoom 2006-08-22
  • 打赏
  • 举报
回复
function CheckForm(){
var cb=document.getElementsByName("v");
var c=0;
for (i=0;i<cb.length;i++){
if (cb[i].checked){
if(++c>10){
alert("超过10项,不允许提交!");
return false;
}
}
}
}

这个翻译成vbscript是什么?
tokilcoom 2006-08-22
  • 打赏
  • 举报
回复
看看
leohuang 2006-08-21
  • 打赏
  • 举报
回复
凑个热闹
-----------------------------------------------------------
<script>
function CheckForm(){
var cb=document.getElementsByName("checkbox1");
var c=0;
for (i=0;i<cb.length;i++){
if (cb[i].checked){
if(++c>10){
alert("超过10项,不允许提交!");
return;
}
}
}
}
</script>
impeller 2006-08-21
  • 打赏
  • 举报
回复
正解
penglewen 2006-08-21
  • 打赏
  • 举报
回复
楼上的两位都是正确..
kafly 2006-08-21
  • 打赏
  • 举报
回复

<script>
function CheckForm(){
var ifcheck=document.getElementsByName("checkbox1");
var checkitem=0;
for (i=0;i<ifcheck.length;i++){
if (ifcheck[i].checked){
checkitem+=1; }
}
if (checkitem>10){
alert("超过10项,不允许提交!")
return false;
}
return true;
}
</script>

<form method="post" name="form1" onSubmit="return CheckForm();" action="">
<input type="checkbox" name="checkbox1">
<input type="checkbox" name="checkbox1">
<input type="checkbox" name="checkbox1">
<input type="checkbox" name="checkbox1">
<input type="checkbox" name="checkbox1">
<input type="checkbox" name="checkbox1">
<input type="checkbox" name="checkbox1">
<input type="checkbox" name="checkbox1">
<input type="checkbox" name="checkbox1">
<input type="checkbox" name="checkbox1">
<input type="checkbox" name="checkbox1">
<input type="checkbox" name="checkbox1">
<input type="Submit" name="checkbox1">
</form>
tokilcoom 2006-08-21
  • 打赏
  • 举报
回复
具体怎么操作呢 能写详细点吗 谢谢
liangjianshi 2006-08-21
  • 打赏
  • 举报
回复
function aa(){
var ifcheck=document.getElementsByName("checkbox1");
var checkitem=0;
for (i=0;i<ifcheck.length;i++){
if (ifcheck[i].checked){
checkitem+=1; }
}
if (checkitem>10){alert("超过10项,不允许提交!")
return false;
}

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧