首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > ASP >

FOR EACH name IN Request.Form("rc") 有关问题 解决就给分

2012-03-04 
FOR EACH name IN Request.Form(rc) 问题解决就给分我的代码如下:htmlheadmetahttp-equiv Conten

FOR EACH name IN Request.Form("rc") 问题 解决就给分
我的代码   如下:

<html>
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 ">
<title> 无标题文档 </title>
</head>
<body   >
<form   name= "form1 "   method= "post "   action= " ">
    <table   width= "200 "   border= "1 ">
        <tr>
            <td> <label>
                <input   type= "checkbox "   name= "rc "   value= "checkbox ">
            </label> </td>
            <td> &nbsp; </td>
        </tr>
        <tr>
            <td> <label>
                <input   type= "checkbox "   name= "rc "   value= "checkbox ">
            </label> </td>
            <td> </td>
        </tr>
        <tr>
            <td> <label>
                <input   type= "checkbox "   name= "rc "   value= "checkbox ">
            </label> </td>
            <td> </td>
        </tr>
        <tr>
            <td> <%
  dim     aa
          aa=0
          FOR   EACH   name   IN   Request.Form( "rc ")
              aa=aa+1
          NEXT
IF     aa> 3   THEN
              Response.write   " <Script   language=JavaScript> alert( '你选择太多了! ') </Script> ; "          
%> </td>
            <td> &nbsp; </td>
        </tr>
    </table>
</form>
</body>
</html>


我想解决的问题   如下:
我想通过
dim     aa
          aa=0
          FOR   EACH   name   IN   Request.Form( "rc ")
              aa=aa+1
          NEXT
IF     aa> 3   THEN
              Response.write   " <Script   language=JavaScript> alert( '你选择太多了! ') </Script> ; "          

这个语句     把 "已经 "选中的复选框     通过循环读出的个数     如果大于3个就提示错误    
注意
是   已经 "选中的复选框


先谢谢大家了

------解决方案--------------------


这个一般用客户端脚本进行控制
修改后代码如下

<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<title> 无标题文档 </title>
<script language=javascript>
function chkval(name,num)
{var obj=document.getElementsByName(name);
var j=0;
for(i=0;i <obj.length;i++)
if (obj[i].checked)
{j++;
if (j> num)
{
alert( '最多可以选择 '+num+ '个! ');
obj[i].checked=false;
}
}
}
</script>
</head>
<body >
<form name= "form1 " method= "post " action= " ">
<table width= "200 " border= "1 ">
<tr>
<td> <label>
<input type= "checkbox " name= "rc " value= "checkbox " onclick=chkval( 'rc ',2)>
</label> </td>
<td> &nbsp; </td>
</tr>
<tr>
<td> <label>
<input type= "checkbox " name= "rc " value= "checkbox " onclick=chkval( 'rc ',2)>
</label> </td>
<td> </td>
</tr>
<tr>
<td> <label>
<input type= "checkbox " name= "rc " value= "checkbox " onclick=chkval( 'rc ',2)>
</label> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> &nbsp; </td>
</tr>
</table>
</form>
</body>
</html>

热点排行