简体   繁体   English

根据我们通过按钮选择的行从数据库设置值

[英]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”。

当我们点击按钮'pilih'

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.

相关问题 根据从MySQL数据库返回的JSON将单选按钮设置为选中状态 - Set radio button to checked based on returned JSON from MySQL database 将数据库中的特定行设置为下拉菜单的默认值 - Set specific row from database as default value for drop down menu 根据从数据库检索的值,检查表单上的单选按钮 - check radio button on a form based on value retrieved from database 根据从AngularJS中的REST接收的值设置单选按钮状态 - Set radio button state based on a value received from REST in AngularJS 根据ID搜索,将值从数据库设置为文本框 - Set value from database to textbox based on search by id 在初始加载时根据DropdropList中的值(由数据库填充)设置文本框 - Set TextBox Based on Value From DropdownList (populated by database) on initial Load 单击按钮时显示数据库中的Wordpress数据库自定义表行列值 - Showing a Wordpress Database custom table row column value from the database on button click 从单选按钮获取价值以选择HTML中的图像 - Take value from radio button to choose an image in html 根据数据库值有条件地显示按钮 - Show button conditionally, based on database value 根据单选按钮选择设置隐藏值 - Set hidden value based on radio button selection
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM