在a.php页面上有一个文本和按钮控件
<input name="txtStfID" type="text" id="txtStfID" size="10" />
<input name="btnSearchName" type="button" id="btnSearchName" value="查询员工号" onclick="javascript:window.open('b.php','查询员工工号','directories=no,width=450,height=350');" />
打开b.php页面后,与数据库连接,利用员工姓名查询到员工号
<input name="txtName" type="text" id="txtName" />
<input name="btnSearch" type="submit" id="btnSearch" value="查询姓名" />
</p>
<?php
if($_POST['btnSearch']){
$name = $_POST['txtName'];
$sql= "select * from staff where Stf_name like '%$name%'";
$result = mysql_query($sql);
?>
<table border="0">
<tr>
<td width="40"> </td>
<td width="80">员工号</td>
<td width="100">员工姓名</td>
<td width="100">所属部门</td>
</tr>
<?php
while($row=mysql_fetch_array($result)){
?>
<tr>
<td height="25"><input type="radio" name="rb_id" value="<?=$row['Stf_id']?>" onclick="getID();" /></td>
<td width="80" height="25" ><?=$row['Stf_id']?></td>
<td width="100" height="25" ><?=$row['Stf_name']?></td>
<td width="100" height="25"><?=$row['Stf_department']?></td>
</tr>
<?php
}
?>
<tr>
<td height="30" colspan="4" align="center"><input type="submit" name="Submit" value="确定" />
</td>
</tr>
</table>
<?php
}
?>然后我想把员工号再传回给a.php页面的txtStfID文本控件,我应该怎么实现。
有没有哪位大侠帮帮忙,指点一下!
谢谢
<input name="txtStfID" type="text" id="txtStfID" size="10" />
<input name="btnSearchName" type="button" id="btnSearchName" value="查询员工号" onclick="javascript:window.open('b.php','查询员工工号','directories=no,width=450,height=350');" />
打开b.php页面后,与数据库连接,利用员工姓名查询到员工号
<input name="txtName" type="text" id="txtName" />
<input name="btnSearch" type="submit" id="btnSearch" value="查询姓名" />
</p>
<?php
if($_POST['btnSearch']){
$name = $_POST['txtName'];
$sql= "select * from staff where Stf_name like '%$name%'";
$result = mysql_query($sql);
?>
<table border="0">
<tr>
<td width="40"> </td>
<td width="80">员工号</td>
<td width="100">员工姓名</td>
<td width="100">所属部门</td>
</tr>
<?php
while($row=mysql_fetch_array($result)){
?>
<tr>
<td height="25"><input type="radio" name="rb_id" value="<?=$row['Stf_id']?>" onclick="getID();" /></td>
<td width="80" height="25" ><?=$row['Stf_id']?></td>
<td width="100" height="25" ><?=$row['Stf_name']?></td>
<td width="100" height="25"><?=$row['Stf_department']?></td>
</tr>
<?php
}
?>
<tr>
<td height="30" colspan="4" align="center"><input type="submit" name="Submit" value="确定" />
</td>
</tr>
</table>
<?php
}
?>然后我想把员工号再传回给a.php页面的txtStfID文本控件,我应该怎么实现。
有没有哪位大侠帮帮忙,指点一下!
谢谢
应该说是一个被选中的radiobutton的值,该值为员工号
在JS中,window.opener只是对弹出窗口的母窗口的一个引用
onclick="getID(this.value);"
function getID(val)
{
window.opener.document.getElementById("txtStfID").value=val;
}
可以有几个方法:
1.b.php页面提交的action设置为a.php,在a.php中取值:$num=isset($_POST['rb_id'])? '$_POST['rb_id']':'';2.session。
{
window.opener.document.getElementById("txtStfID").value=val;
window.close();
}然后给你的确定按钮加上onclick事件。
function getID()
{
var val = document.getElementsByName("rb_id");
for(var i=0;i<val.length;i++){
if(val[i].checked){
window.opener.document.getElementById("txtStfID").value=val.value;
}
window.close();
}
为什么这样就没反应了
是不是我哪里写错了
function getID()
{
var val = document.getElementsByName("rb_id");
var html='';
for(var i=0;i<val.length;i++){
if(val[i].checked){
html+=val[i].value;
}
window.opener.document.getElementById("txtStfID").value=html;
window.close();
}