请问,如何将子页面option值全部传递给父页面的text?
父页面代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
<title> 无标题文档 </title>
</head>
<body>
<form name= "form1 " id= "form1 " method= "post " action= " ">
<input name= "userid " type= "text " id= "userid " value= " " />
<a href= "# " onclick= "window.open( 'friendlist.htm ', 'newwindow ', 'height=380, width=600, top=10, left=200, top=60, toolbar=no, menubar=no, scrollbars=yes,resizable=no,location=no, status=no ') "> 选择名单 </a>
</form>
</body>
</html>
子页面friendlist.htm代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
<title> 好友名单 </title>
<style type= "text/css ">
<!--
* {
margin:0;
border:0;
padding:0;
}
body {
font:12px Arial;
background:#fff;
color:#333;
}
td {
padding:5px;
}
.list {
color:#333;
width:120px;
font:12px/20px Arial;
background:#fff;
}
.button {
display:block;
width:61px;
line-height:19px;
text-align:center;
background:url(images/button1.gif) no-repeat;
color:#000;
text-decoration:none;
}
.button1 {
width:73px;
font:12px/22px Arial;
text-align:center;
background:url(images/button6.gif) no-repeat;
color:#000;
text-decoration:none;
}
-->
</style>
</head>
<body>
<script language= "JavaScript ">
function copyToList(from,to) //from表示:包含可选择项目的select对象名字 to表示:列出可选择项目的select对象名字
{
fromList = eval( 'document.forms[0]. ' + from);
toList = eval( 'document.forms[0]. ' + to);
if (toList.options.length > 0 && toList.options[0].value == 'temp ')
{
toList.options.length = 0;
}
var sel = false;
for (i=0;i <fromList.options.length;i++)
{
var current = fromList.options[i];
if (current.selected)
{
sel = true;
if (current.value == 'temp ')
{
alert ( '你不能选择这个项目! ');
return;
}
txt = current.text;
val = current.value;
toList.options[toList.length] = new Option(txt,val);
fromList.options[i] = null;
i--;
}
}
if (!sel) alert ( '你还没有选择任何好友 ');
}
function ToOption(sel_dest)
{
var value=[];
for(i=0;i <sel_dest.options.length;i++){
window.opener.document.form1.userid.value = sel_dest.options[i].text;
}
window.close();
}
</script>
<form name= "form1 " id= "form1 " method= "post " action= " " onSubmit= "allSelect() ">
<table width= "360 " border= "0 " cellspacing= "0 " cellpadding= "0 ">
<tr>
<td width= "140 "> <select name= "possible " size= "8 " multiple= "multiple " class= "list " id= "possible ">
<option value= "1 "> Friend </option>
<option value= "2 "> Tom </option>
<option value= "3 "> Tony </option>
<option value= "4 "> Luke </option>
<option value= "5 "> Simmy </option>
</select> </td>
<td width= "80 "> <a href= "javascript:copyToList( 'possible ', 'chosen ') " class= "button "> 添加 </a> <br />
<a href= "javascript:copyToList( 'chosen ', 'possible ') " class= "button "> 删除 </a> </td>
<td width= "140 "> <select name= "chosen " size= "8 " multiple= "multiple " class= "list " id= "chosen ">
<option value= "temp "> 请选择你的好友 </option>
</select> </td>
</tr>
<tr>
<td> </td>
<td height= "30 "> <input type= "submit " name= "Submit " value= "确 定 " class= "button1 " onClick= "ToOption(chosen); " /> </td>
<td> </td>
</tr>
</table>
</form>
</body>
</html>
现在我的userid文本框只能获取一个名单,请问我想获取全部的被选择的值如何修改?谢谢了
[解决办法]
var tempstr = " ";
for(var i=0;i <sel_dest.length;i++)
{
tempstr += sel_dest.options[i].text + ", ";
}
window.opener.document.form1.userid.value = tempstr;