假设现在有文本框1和文本框2,1用来输入工号,根据输入的工号值去数据库中的用户表查询对应的姓名,将查询的结果作为文本框2的内容。
1、文本框1加上onChange()方法:
<input type="text" name="account" id="account" style="width: 80px;" οnchange="accountToName(this.id)"/>
<input type="text" name="author_name" id="author_name" style="width: 80px;"/>
2、查询的sql语句:
select name author_name
from sys_p_user
where account=[account]
3、查值填充:
function accountToName(account) {
var gonghao = document.getElementById("account").value;
rdcp.request("!gh/manu/~query/Q_ACCOUNT_TO_NAME", 'account=' + gonghao, function (data) {
author_name = data.body.author_name;
$("#author_name").val(author_name);
});
}