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

标签 php jquery

仅在显示第一次执行表并且在新选项卡中显示outs_print.php 文件后,再次执行outward_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

关于php - 单击按钮后我想显示表格并打开新窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36567692/

相关文章:

php - 未定义的类常量 'PDO::FETCH_DEFAULT'

javascript - 使用 Node.js 保存压缩字符串

php - Laravel 5.2 事件处理错误

jquery - 在 Eonasdan Bootstrap 日期选择器中设置默认日期

javascript - jquery 或 javascript 中是否有 isTextSelected() 的替代方法?

php - 用于社交网络项目的带有 PHP api 或 PHP 脚本的视频托管

php - Laravel - 防止多个请求同时创建重复记录

jquery - 第二次调用对话框后,Telerik DropDownList 在 JQuery 对话框中被禁用

jquery - 根据选择更改背景图像

jquery - jQuery 中的 load()