从数据库中选择名称后,如何自动填写输入字段? [英] How to fill input field automatically when name is selected from database?

查看:52
本文介绍了从数据库中选择名称后,如何自动填写输入字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要填写的表格,它的一个字段是雇员姓名,我从一个名为tbl_employee的数据库表中选择了它的值,每个名字都有存储在同一张表中的代号,但是我有一个问题,因为我不知道要使用什么代码来自动填充名为codename的输入字段.以下是我的html代码

I have a form that need to be filled up, one of its field is employee name, I selected its value from a database table called tbl_employee, each name has codename that stored in the same table, but I have a problem, because I dont know what code to be used to automatically filled the input field called codename. the following is my html code

<div class="form-group">
 <label>Employee Name</label>
  <select name="employee" onchange="getEmp(this.value)" class="form-control">
    <option value="">Select Employee</option>
    <?php foreach($emps as $emp) : ?>
      <option value="<?php echo $emp["employee_id"]; ?>"><?php echo $emp["surname"] . ', ' . $emp["firstname"]; ?></option>
    <?php endforeach; ?>
  </select>
  <div class="help-block with-errors"></div>
</div>
<div class="form-group">
  <label>Code Name</label>
  <input class="form-control" name="codenamer" type="text"/>
  <div class="help-block with-errors"></div>
</div>

您的回复受到高度赞赏

推荐答案

此问题已解决.我只是改写上面给出的代码.

this issue is already solve. i've just rephrase the codes given above.

<script type="text/javascript">
    function getEmp(codename){
         var res = codename.split(" ", 1 );
        document.getElementById("codenamer").value=res;
    }
</script>

呼叫者进入我的输入字段

and caller to my input field

id="codenamer"

感谢所有受访者.

这篇关于从数据库中选择名称后,如何自动填写输入字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆