[英]How do I populate a popup window with values from a for loop in javascript?
[英]How do you populate values from a child popup window to the parent window?
我有一些輸入字段,我想從帶有表記錄的彈出窗口中填充。 當我單擊選擇按鈕以填充記錄時,我僅獲得第一條記錄。 即使我選擇了最后一條記錄。
我有兩個單獨的文件。 文件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>
您需要進行的所有修改都可以使其獲得唯一的ID(如果您仍想使用ID來訪問字段,則可以多次復制JS代碼),
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.