我有一个带有 .php 扩展名的父页面和子页面。看来我的代码是正确的。但是,当我单击子页面上的提交按钮时,子页面不会关闭,并且单元格表中的值无法传递到父页面上的文本字段中。这是代码:
父页面代码:
<html>
<head>
</head>
<body>
<form method=post action='' name='f1'>
<font size=2 face='Verdana'>Your Name</font><input type=text name='p_name' size='8'> <a href="javascript:void(0);" NAME="My Window Name" title=" My title here " onClick=window.open("target.php","Ratting","width=1000,height=500toolbar=1,status=1,");>Click here to open the child window</a>
</form>
</body>
</html>
子页面代码(parrent.php):
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<script langauge="javascript">
function post_value(id){
opener.document.f1.p_name.value = document.forms[id].c_name.value;
self.close();
}
</script>
</head>
<body>
<?php
$host="localhost";
$username="root";
$password="";
$db_name="rawatinap";
mysql_connect("$host", "$username", "$password")or die("failed db connection");
mysql_select_db("$db_name")or die("cannot select db");
$edit = mysql_query("SELECT id_obat from obat");
?>
<table >
<?php
$id=0;
while($rows=mysql_fetch_array($edit)){
echo " <form name=$id method='post' action=''><tr>
<td><input type=\"text\" name=\"c_name\" size=\"30\" value=\"$rows[id_obat]\" /></td>
<td><input type=button value='Submit' onclick='post_value('$id')</td></tr>
</form>";
$id++;
}
?>
</table>
</body>
</html>
最佳答案
好的,我通过失去时间得到了答复。这是我的正确代码:
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<script langauge="javascript">
function post_value(id){
opener.document.f1.p_name.value = document.forms[id].c_name.value;
self.close();
}
</script>
</head>
<body>
<?php
$host="localhost";
$username="root";
$password="";
$db_name="rawatinap";
mysql_connect("$host", "$username", "$password")or die("Gagal terkoneksi dengan database");
mysql_select_db("$db_name")or die("Tidak bisa memilih database");
$edit = mysql_query("SELECT id_obat from obat");
?>
<table >
<?php
$id=0;
while($rows=mysql_fetch_array($edit)){
echo "
<form name=$id method='post' action=''><tr>
<td><input type=\"text\" name=\"c_name\" size=\"30\" value=\"$rows[id_obat]\" /></td>
<td><input type=button value='Submit' onclick='post_value($id)'</td></tr>
</form>";
$id++;
}
?>
</table>
</body>
</html>
关于php - 无法将值从子页面传递到父页面且无响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20613972/