Function CheckForm()
  set cb=document.getElementsByName("v")
  c=0
  for each e in cb
    if e.checked Then
   c = c+1
      if c > 10 Then
        alert("超过10项,不允许提交!")
        CheckForm = false
      end if
    end if
  next
End Function

解决方案 »

  1.   

    vbscript 使用 function吗? 不是用sub的吗?
      

  2.   

    Sub是过程,不带返回值的,Function是函数,带返回值。
      

  3.   

    <%
    Function CheckForm()
      set cb=document.getElementsByName("v")
      c=0
      for each e in cb
        if e.checked Then
       c = c+1
          if c > 10 Then
            alert("超过10项,不允许提交!")
            CheckForm = false
          end if
        end if
      next
    End Function
    %>document.write ("<form method='post' onSubmit='return CheckForm();' action='votes.asp'><table border='1' cellpadding='5' cellspacing='0' bordercolordark='#f7f7f7' bordercolorlight='#cccccc' class='inputt'>");点选超过10项的话,就弹出对话框 不让提交。    这样写有什么错吗?   页面能出来 但是没效果
      

  4.   

    你把服务器端的脚本和客户端的弄混了
    document.getElementsByName是客户端的脚本用法,
      

  5.   

    哦  小弟不是很了解   
    希望大虾能帮忙解决这个小问题document.write ("<form method='post' action='votes.asp'><table border='1' cellpadding='5' cellspacing='0' bordercolordark='#f7f7f7' bordercolorlight='#cccccc' class='inputt'>");
    这个是源文件的内容
    我想加个程序判断一下,别选超过10项,如果超过了10项,就不让提交万分感谢   如果需要的话 下面的是整个源程序<!-- #include file="conn.asp"-->
    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' 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='submit1' value='投票' class='inputt'>&nbsp;&nbsp;<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>");
      

  6.   

    差不多这样就可以了
    document.write ("<form method='post' action='votes.asp' onsubmit="return CheckForm()"><table border='1' cellpadding='5' cellspacing='0' bordercolordark='#f7f7f7' bordercolorlight='#cccccc' class='inputt'>");
      

  7.   

    document.write ("<form method='post' action='votes.asp' onsubmit=‘return CheckForm()’><table border='1' cellpadding='5' cellspacing='0' bordercolordark='#f7f7f7' bordercolorlight='#cccccc' class='inputt'>");