首页 > 解决方案 > 如何将值从子弹出窗口填充到父窗口?

问题描述

我有输入字段,我想从带有表记录的弹出窗口中填充。当我单击选择按钮填充记录时,我只得到第一条记录。即使我选择了最后一条记录。

我有两个单独的文件。文件 A 和文件 B。文件 A 激活文件 B 的弹出窗口。文件 A

 <div class="input-group">
        <input type="text" class="form-control" name="munit">
        <span class="input-group-addon success" onclick="myFunction()"> <span class="glyphicon glyphicon-ok"></span></span>
    </div>
<input type="text" id="managementu" readonly="readonly" />
<input type="text" id="department" readonly="readonly" />
<input type="text" id="division" readonly="readonly" />

文件 B。

 <table class="table">
                       <thead>
                             <tr>
                      <th>Management Unit</th>
                      <th>Department</th>
                      <th>Division</th>
                      <th>Action</th>
                    </tr>
                  </thead>
                  <tbody id="myTable">
                   <?php foreach ($records as $row){?>
                    <tr>
                      <td><?php echo $rows['Description']; ?></td>
                      <td><input type="text" id="dept" value="<?php echo $rows['Department_Description']; ?>"></td>
                      <td><input type="text" id="divi" value="<?php echo $rows['Division_Description']; ?>"/></td>
                      <td><input type="text" id="reg" value="<?php echo $rows['Region_Description']; ?>"/></td>
                      <td><input type="text" id="dist" value="<?php echo $rows['District_Description']; ?>"/></td>
                      <td><button onclick="copyFunc<?php echo $rows['Code']; ?>()" >Select</button></td>
                    </tr><?php }?>



                <script>
                function copyFunc() {
                   if (window.opener != null && !window.opener.closed) {
                            var division = window.opener.document.getElementById("division");
                            division.value = document.getElementById("divi").value;

                                 var department = window.opener.document.getElementById("department");
                            department.value = document.getElementById("dept").value;

                            var region = window.opener.document.getElementById("region");
                            region.value = document.getElementById("reg").value;

                            var district = window.opener.document.getElementById("district");
                            district.value = document.getElementById("dist").value;
                        }
                    window.close();
                }
                </script>

                <script>
                $(document).ready(function(){
                  $("#myInput").on("keyup", function() {
                    var value = $(this).val().toLowerCase();
                    $("#myTable tr").filter(function() {
                      $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
                    });
                  });
                });
                </script>

                 </tbody>
                </table>
                </body>
                </html>

标签: javascriptphpjquery

解决方案


您只需要修改它以获得唯一的 ID(然后多次复制 JS 代码,如果您仍想使用 ID 访问字段),


推荐阅读