Question

I have a parent and child page with .php extension. It seems my code is correct. But when I click submit button on child page, the child page would not close and the value from my cell table is cannot passed into text field on parent page. Here is the code:

Parent page's code :

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

Child page's code (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>
Was it helpful?

Solution

Okay, i got answer by lost of hours time. Here is my correct code :

<!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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top