【问题标题】:Failed to Passing Value from Child page to Parent page with no Response无法将值从子页面传递到父页面而没有响应
【发布时间】:2013-12-16 15:01:32
【问题描述】:

我有一个带有 .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'>&nbsp;<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>

【问题讨论】:

  • 你想达到什么目的?
  • @ManojPurohit 只是将子页面上的表格单元格“c_name”中的值传递到父页面上的文本“p_name”中。但是无法将值传给父页面,子页面也无法关闭。

标签: php jquery html mysql popupwindow


【解决方案1】:

好的,我通过浪费时间得到了答案。这是我的正确代码:

<!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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多