如何将值从子弹出窗口填充到父窗口?

时间:2019-02-06 08:32:02

标签: javascript php jquery

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

我有两个单独的文件。文件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>

1 个答案:

答案 0 :(得分:0)

您需要进行的所有修改,以便获得唯一的ID(如果您仍想使用ID来访问字段,则可以多次复制JS代码)