就是无论用户点没点这个多选列表 提交给服务器后 都是把所有选项的value都穿过来了
有什么解决办法么 ?
在表单里加入一个hidden,当用户提交时,你把selected中所有的option的值都以字符串形式写入
hidden,当然,你要用特殊的字符将值分开,然后在服务器上读hidden的值,再把每个值根据你的
分隔符取出来
使用框架
for(i=0;i<parent.f1.form1.select1.options.length;i++)
parent.f2.form1.select1.options[i].value=parent.f1.form1.select1.options[i].value;
我没asp环境,写个大概给你吧.
f1:main frame
f2:width为0的框架,用来保存你的数据.
生成页面的时候你把select里面的数据保存到f2中,提交后到本页(f1),这样就可以通过框架访问到f2的数据了,格式如上.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<form name="form1" method="post" action="run_bc.asp" onsubmit="return check_frm()">
<p>
<select name="selt1" size="6" multiple>
<option value="1">测试文字处理1</option>
<option value="2">测试文字处理2</option>
<option value="3">测试文字处理3</option>
<option value="4">测试文字处理4</option>
<option value="5">测试文字处理5</option>
<option value="6">测试文字处理6</option>
</select>
</p>
<p>
<input name="bc" type="submit" id="bc" value="提交">
</p>
</form>
</body>
</html>
<script language=vbscript>
function check_frm()
for i=0 to document.all("selt1").length-1
document.all("selt1")(i).selected=true
next
check_frm=false
//以上false改为true就可以了
end function
</script>
<form name="form1" method="post" action="run_bc.asp" onsubmit="return check_frm()">
<p>
<select id="selt2" size="6" multiple>
<option value="1">测试文字处理1</option>
<option value="2">测试文字处理2</option>
<option value="3">测试文字处理3</option>
<option value="4">测试文字处理4</option>
<option value="5">测试文字处理5</option>
<option value="6">测试文字处理6</option>
</select>
<input type=hidden name="selt1" value="">
</p>
<p>
<input name="bc" type="submit" id="bc" value="提交">
</p>
</form>
</body>
</html>
<script>
function check_frm()
{
l=document.getElementById("selt2")
for(i=0;i<l.options.length;i++)
document.getElementById("selt1").value+=l.options[i].value+","
document.getElementById("selt1").value = document.getElementById("selt1").value.substr(0,document.getElementById("selt1").value.length-1)
alert(document.getElementById("selt1").value)
}
</script>