单击按钮后,我想显示表格并打开新窗口


After button click I want to display the table and open new window

只有在显示了第一个执行表并且outs_print.php文件显示在新选项卡中之后,再次执行的outer_print.php文件才会显示在同一选项卡中。

单击按钮后,我希望在新选项卡中显示表格(outs_print.php文件)。

<!doctype html>
<body>
  <form name="out_print" action="out_print.php" method="post">
  <table class="table_1">
  <tr><td><label>Date Range From</label></td>
  <td><input type="date" name="from" /></td>
  <td><label>To</label></td>
  <td><input type="date" name="to"/></td></tr>
  <tr><td><label>Name</label></td>
  <td><input type="text" name="name" /></td></tr></table>
  <input type="submit" name="submit" value="Search" onclick="myFunction();"  class="button3"/>
  <script>
  function myFunction()
  {
    document.out_print.action = "outs_print.php";
    document.out_print.submit();                
  }
  </script>
</form>
</body>
</html>

outs_print.php

<?php
    $connection = mysql_connect("localhost", "root", "");
    $db = mysql_select_db("prs", $connection);
    if(isset($_POST['submit'])){    
    $name = $_POST['name'];
    $from = $_POST['from'];
    $to = $_POST['to'];
    if($name !=''||$from !=''||$to !='')
    {
?>
<html>
<body>
    <table border="1" bordercolor="#d6d6d6" class="tabl">
    <thead bgcolor="#FAFAFA">
    <tr>
    <th>No</th>
    <th>Date</th>
    <th>Name</th>
    <th>Price</th>
    </tr>  
    </thead>
    <tbody>
    <?php
        $sql = "SELECT * FROM out WHERE (date between '$from' and '$to') AND (name = '$name')";
        $records=mysql_query($sql);
        while($out=mysql_fetch_assoc($records))
        {
             echo "<tr>";
             echo "<td>".$out['no']."</td>";
             echo "<td>".$out['date']."</td>";
             echo "<td>".$out['name']."</td>";
             echo "<td>".$out['price']."</td>";
             echo "</tr>";
        }
    ?>
          <script type="text/javascript">
            alert("Okay");
            var win = window.open("out_print.php", "out_print.php");
            win.focus();
          </script>
    <?php
       }
    }
    ?>
    </tbody>
    </table> 
</body>
</html>

这里的其他答案是正确的,但target="_blank"将在每次表单提交时创建一个新的选项卡/窗口。

如果您希望在第一次提交表单时启动一个新的选项卡/窗口,并且任何后续提交的表单都希望在第一个提交时创建的选项卡/窗中返回结果,则为目标提供一个名称即可。

<form name="out_print" method="post" action="out_print.php" target="out_print_response">
....

http://www.w3schools.com/tags/att_form_target.asp

只需在表单元素中添加target="_blank":)

http://www.w3schools.com/tags/tag_form.asp

像这样添加target="_blank"

<form name="out_print" action="out_print.php" method="post" target="_blank">

表单中的target属性指定在哪里显示提交表单后收到的响应。target="_blank"new tab中显示响应。

希望这能有所帮助。