i want autofill in "Nama Pegawai" if i select "Id Pegawai"
please somebody who understand what a code to make autofill help me. i've tried but it not work.
this is my code:
<div class="form-group">
<label>Id Pegawai</label>
<select name="id_pegawai" id="id_pegawai" onkeyup="autofill()" class ="form-
control">
<option value="#" disabled selected >Pilih ID Pegawai</option>
<?php
@mysql_connect("localhost", "root", "");
mysql_select_db("gorden_interior");
$sql = mysql_query("SELECT * FROM pegawai");
if(mysql_num_rows($sql) != 0){
while($pegawai = mysql_fetch_assoc($sql)){
echo '<option>'.$pegawai['id_pegawai'].'</option>';
}
}
?>
</select>
</div>
<div class="form-group">
<label>Nama Pegawai</label>
<input type="text" name="nama_pegawai" id="nama_pegawai" readonly
class="form-control">
</div>
</table>
</form>
<script href="<?php echo base_url('assets/javascript/jquery-3.1.1.min.js');?
>"></script>
<script type="text/javascript">
function autofill(){
var id_pegawai = $("#id_pegawai").val();
$.ajax({
url : 'proses.php',
data : 'id_pegawai='+id_pegawai,
}).success(function(data){
var json = data,
obj = JSON.parse(json);
$("#nama_pegawai").val(obj.nama_pegawai);
});
}
</script>
Thank You