PHP使用子窗口中的单选按钮确定从子窗口插入父窗口textarea的内容

时间:2012-08-24 03:08:08

标签: php javascript mysql window parent

大家好我是php的新手,想知道如果可以通过子窗口中的单选按钮确定从子窗口插入父窗口textarea的内容。我应该怎么做呢?如果有人能提供一些帮助,我将非常感激。下面是代码。感谢。

父窗口:

<head>
<script type='text/javascript'>
window.onload = function()
{
  document.getElementById('b1').onclick = openChild;
}
function openChild()
{
  this.disabled = false;
  xWinOpen('retrievemath.php');
}
var xChildWindow = null;
function xWinOpen(sUrl)
{
  // Modify 'features' to suit your needs:
  var features = "left=100,top=100,width=400,height=400,location=0,menubar=0," +
    "resizable=1,scrollbars=1,status=0,toolbar=0";
  if (xChildWindow && !xChildWindow.closed) {xChildWindow.location.href  = sUrl;}
  else {xChildWindow = window.open(sUrl, "myWinName", features);}
  xChildWindow.focus();
  return false;
}
</script>
<script src="ckeditor/ckeditor.js"></script>

</head>
<body>
    <textarea class="ckeditor" cols="80" id="editor1" name="editor1" rows="10" ></textarea>
<form>
<input type="button" id ="b1" onClick="myPopup2()" value="POP2!">
</form>
<p onClick="myPopup2()">CLICK ME TOO!</p>
</body>

子窗口:

<?php
include ('database_connection.php');
  $dbConn = mysql_connect('localhost', 'root', '')
             or trigger_error(mysql_error(), E_USER_ERROR);
  // select the database for use
  mysql_select_db('test', $dbConn);
$query_retrieve_expression = "SELECT * FROM math";
 $queryResource = mysql_query($query_retrieve_expression, $dbConn) or die(mysql_error());
?>

<head>

<script type='text/javascript'>
window.onload = function()
{
  document.getElementById('f1').onsubmit = sendToParent;
}
function sendToParent()
{
  if (window.opener) {
    var cta = document.getElementById('<?php echo $row['mathID']?>');
    var pta = window.opener.document.getElementById('editor1');
    pta.value = cta.value;
    window.opener.focus();
  }
  return false;
}
</script>
</head>
<body>
        <form action="retrievemath.php" method="post" id="f1">
<table class="hovertable">
<tr>
    <th>Insert ?</th><th>Expression Name</th><th>Math Expression</th>
</tr>

    <?php
               while($row = mysql_fetch_assoc($queryResource))
               {     
    ?>

                    <tr> 
                    <td><input type="radio" name="insert" id="<?php echo $row['mathID']?>" value="<?php echo $row['expressionname']?>" /> </td> 
                    <td><?php echo $row['expressionname']; ?></td>
                    <td><?php echo $row['mathexpression']; ?></td> 
                    </tr>

    <?php
               }
    ?>


</table>



    <div class="submit">
      <input type="submit" value="Insert" />
    </div>
        </form>
</body>

1 个答案:

答案 0 :(得分:0)

你可以获得textarea的价值并像这样传递网址

最新功能

function sendToParent()
{
    var cta='';

    var radio=document.getElementsByName("insert");

    for(var i=0;i<radio.length;i++)
    {
        cta+=radio[i].value;
    }

    var pta = var pta = window.opener.document.getElementById("editor1");
    pta.value = cta;
    self.close();
}

您可以像这样在子窗口中获取textarea的值

echo $_GET['data'];

子窗口代码

<head>
<script type='text/javascript'>

 function sendToParent()
{
    var cta='';

    var radio=document.getElementsByName("insert");

    for(var i=0;i<radio.length;i++)
    {
        cta+=radio[i].value;
    }

    var pta =var pta = window.opener.document.getElementById("editor1");
    pta.value = cta;
    self.close();
}
</script>
</head>
<body>
<form action="retrievemath.php" method="post" id="f1">
<table class="hovertable">
<tr>
    <th>Insert ?</th><th>Expression Name</th><th>Math Expression</th>
</tr>
<tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">

</tr>

    <?php
               while($row = mysql_fetch_assoc($queryResource))
               {     
    ?>

                    <tr> 
                    <td><input type="radio" name="insert" id="<?php echo $row['mathID']?>" value="<?php echo $row['expressionname']?>" /> </td> 
                    <td><?php echo $row['expressionname']; ?></td>
                    <td><?php echo $row['mathexpression']; ?></td> 
                    </tr>

    <?php
               }
    ?>


</table>



    <div class="submit">
      <input type="button" value="Insert" onclick="sendToParent();" />
    </div>
        </form>
</body>