我正在尝试从父页面创建一个弹出页面,该页面将向父页面返回一个值并最终关闭。
到目前为止,我所做的是:
main.php:
<tr>
<th>Project Name</th>
<td><input type="text" name="project_name" id="pid" disabled="disabled" />
<input type="button" name="choice" onClick="selectValue('id')" value="?"></td>
</tr>
<head>
<script type="text/javascript">
function selectValue(pid){
// open popup window and pass field id
window.open('search_project.php?id=' + encodeURIComponent(pid),'popuppage',
'width=400,toolbar=1,resizable=1,scrollbars=yes,height=400,top=100,left=100');
}
function updateValue(pid, value){
// this gets called from the popup window and updates the field with a new value
document.getElementById(pid).value = value;
}
</script>
</head>
search_project.php:
<head>
<script>
function closeWin(){
myWindow.close();
}
</script>
<script type="text/javascript">
function sendValue(value)
{
var parentId = <?php echo json_encode($_GET['id']); ?>;
window.opener.updateValue(parentId, value);
window.close();
}
</script>
<?php
$sql = mysql_query("SELECT project_id from prjct where project_id like 'default'");
$num = mysql_num_rows($sql);
<tr>
<td><input type="button" value="Select" onClick="sendValue('<?php echo $sql['project_id']; ?>')" /></td>
<td align="center"><? echo $sql['project_id']; ?></td>
</tr>
因此,应该关闭popup(search_project.php)并在main.php的输入字段中返回project_id的值。但是,当我单击选择按钮时,没有任何反应。弹出窗口不会关闭,并且不会返回该值。似乎sendValue(value)无法正常工作。
需要帮忙。
您是否真的要在此处encodeURIComponent(pid)?
尝试不使用encodeURIComponent:
window.open('search_project.php?id=pid','popuppage',
'width=400,toolbar=1,resizable=1,scrollbars=yes,height=400,top=100,left=100');
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句