利用Javascript从子窗口设置父窗口的值

在Hibernate的一对多数据列表中经常包含这样一个需求:例如在我们添加人员的时候需要选择新添加的这个人属于那一个组,这就要显示组的信息在这里可以用下拉框实现,但是更好的实现是弹出一个新的窗口在新弹出的窗口中显示所有的组然后进行选择!

//添加页面

<tr>
<td class="tdEditLabel" >所属组</td>
<td class="tdEditContent"><input type="text"
id="orgName" disabled="disabled">
<input type="hidden" name="orgId" id="orgId">
<input type="button" value="选择"
onclick="openWin('person!selectOrg.action','selectparties',800,600,1);">
</td>
<td class="tdEditLabel" >姓名</td>
<td class="tdEditContent"><input type="text" name="name"></td>
</tr>


//openWin函数

function openWin(f,n,w,h,s){
sb = s == "1" ? "1" : "0";
l = (screen.width - w)/2;
t = (screen.height - h)/2;
sFeatures = "left="+ l +",top="+ t +",height="+ h +",width="+ w
+ ",center=1,scrollbars=" + sb + ",status=0,directories=0,channelmode=0";
openwin = window.open(f , n , sFeatures );
if (!openwin.opener)
openwin.opener = self;
openwin.focus();
}


//调用函数的时候弹出一个新的窗口把所有的组显示出来
设置父窗口的函数:

function selectOrg(orgId,orgName){
window.opener.document.getElementById("orgName").value = orgName;
window.opener.document.getElementById("orgId").value = orgId;
window.close();
}


//调用页面的函数实现选择
<td align="center" vAlign="middle">
<input type="radio" id="selectOrgId" onclick="selectOrg('<s:property value="id"/>','<s:property value="orgName"/>');" />
</td>


最终的页面效果:
[img]http://dl.iteye.com/upload/attachment/219685/33e1dc18-71c6-3add-b71f-3f2c82a24e50.jpg[/img]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值