[英]Set value from database based on row we choose by button
I want to make a form for my office, where users can fill the form without manually typing. 我想为我的办公室制作一个表格,用户无需手动输入即可填写表格。
Just search from the popup browser, and find their data and automatically set in fields. 只需从弹出浏览器中搜索,然后找到其数据并自动在字段中进行设置即可。
This is form display, 这是表格显示
when we click the blue file icon to open new popup window 当我们单击蓝色文件图标以打开新的弹出窗口时
And this is new popup window, search display. 这是新的弹出窗口,显示搜索。
When we click button 'pilih' i want ('nik, nama_karyawan, departemen, jabatan') to automatically set in form display. 当我们单击按钮“ pilih”时,我要自动在表单显示中设置“ nik,nama_karyawan,departemen,jabatan”。
What you need is to send parameters to opener window. 您需要将参数发送到打开器窗口。 You can do it easily by using window.opener Below is the sample code that works fine for me:
您可以使用window.opener轻松完成此操作。以下是适合我的示例代码:
In parent window: 在父窗口中:
<script>
$(document).ready(function(){
$('.btnOpenPopup').click(function(){
window.open("popup.html", "userList", "width=200, height=100");
});
});
</script>
<form name="test">
<label>Name: </label>
<input type="text" name="firstname" id="firstname" />
<a href="javascript:void(0);" class="btnOpenPopup">Open</a>
<br /><br />
<label>Last name:</label>
<input type="text" name="lastname" id="lastname" />
</form>
In popup window: 在弹出窗口中:
<script>
$(document).ready(function(){
$('table tr').click(function(){
firstName = $(this).find('td:eq(1)').text();
lastName = $(this).find('td:eq(2)').text();
window.opener.$('input[name="firstname"]').val(firstName);
window.opener.$('input[name="lastname"]').val(lastName);
window.close();
});
});
</script>
<table width="80%">
<tr>
<td>ID</td>
<td>Name</td>
<td>Last name</td>
</tr>
<tbody>
<tr>
<td>1</td>
<td>John</td>
<td>Something</td>
</tr>
<tr>
<td>8</td>
<td>Albert</td>
<td>Potter</td>
</tr>
<tr>
<td>9</td>
<td>Melis</td>
<td>Some Last Name</td>
</tr>
</tbody>
</table>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.