从数据库中选择名称后,如何自动填写输入字段?

问题描述:

我有一个需要填写的表格,它的一个字段是雇员姓名,我从一个名为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"

感谢所有受访者.