<script>
function check(){
var cidx="";
for(i=0;i<add.cid.length;i++)
{if (add.cid[i].checked)
cidx+=document.add.cid[i].value;
return cidx;
}
}function doMDb(url)
{
var cidx=add.cid.value;
window.showModalDialog("selectb.jsp?cid="+checked()+"",window,'scroll:0;status:0;help:0;resizable:0;dialogWidth:480px;dialogHeight:370px');
return false;
}
</script>
<form action="#" name="add" method="post">
<input type="checkbox" name="cid" value=1>张三
<input type="checkbox" name="cid" value=2>李四
<input type="checkbox" name="cid" value=3>王五
<input type="checkbox" name="cid" value=4>赵六
<input type="checkbox" name="cid" value=5>曾七
<input type="button" name="B1" value="提交" onclick=check()>
</form>
HueVan() 兄弟,这种方法只能获得第一个input的值啊。
就是说,无论你选几个,都只显示第一个的值。
function check(){
var a = new Array();
var cidx="";
for(i=0;i<add.cid.length;i++)
{
if (add.cid[i].checked)
a.push(add.cid[i].value);
//or
//if (add.cid[i].checked)
// a.push(1);
//else
// a.push(0);
}
return a.join('|');
}then in selectb.jsp, on server side, you can do a split
在接受端怎么做呢?我用JSP写的,用JSP的get.ParameterValuse[]数组来实现取得数据。
取得参数
<script>
var a = window.dialogArguments
alert("您传递的参数为:" + a)
</script>
var a = new Array();
for(i=0;i<add.cid.length;i++)
{
if (add.cid[i].checked)
a.push(add.cid[i].value);
}
return a;
}showModalDialog("selectb.jsp", check(), "");
关于split("标志符")[下标]的使用,可以在msdn搜索一下,有很多例子~~
有没有具体的代码呢?
function check(){
var a = new Array();
var cidx="";
for(i=0;i<add.cid.length;i++)
{
if (add.cid[i].checked)
a.push("cid=" + add.cid[i].value);
//or
//if (add.cid[i].checked)
// a.push("cid=" + 1);
//else
// a.push("cid=" + 0);
}
return a.join('&');
}window.showModalDialog("selectb.jsp?cid="+check(),window,'scroll:0;status:0;help:0;resizable:0;dialogWidth:480px;dialogHeight:370px');
string[] s = request.getParameterValues("cid");
问题是在服务器端,也就是selectb.jsp中如何接受这一串参数,又如何把它分解出来呢?
谢谢!!!
问题是,传入的值可能是不同类型,可能传入的是这样的:
id=1
cid=021
cname=wto
cpass=eb
String param = null; while( parameters.hasMoreElements() )
{
param = (String)parameters.nextElement();
String value = request.getParameter( param );
}