如何使用onclick填充多个输入表单

I'm trying to create a live search with AJAX.

Then when I click the result I want the result to fill 5 input fields.

Here is what I have tried:

Here is my cari.php file:

while ($cari_karyawans = $cari_karyawan->fetch()) { ?>
   <div class="result" onclick="fill('nik','<?php echo $cari_karyawans['nik_k_ptayp']; ?>')">
   <div class="result" onclick="fill('nama','<?php echo $cari_karyawans['nama_k_ptayp']; ?>')">
   <div class="result" onclick="fill('lokasi','<?php echo $cari_karyawans['jabatan_k_ptayp']; ?>')">
   <div class="result" onclick="fill('divisi','<?php echo $cari_karyawans['divisi_k_ptayp']; ?>')">
   <div class="result" onclick="fill('jabatan','<?php echo $cari_karyawans['lokasi_k_ptayp']; ?>')">
   <a><small class="text-muted"><i><?php echo $cari_karyawans['nik_k_ptayp']; ?></i></small> / <small class="text-muted"><i><?php echo $cari_karyawans['nama_k_ptayp']; ?></i></small></a>
 </div></div></div></div></div>
<?php } ?>

Here is how I try to fill the result:

function fill(nik, nama, lokasi, divisi, jabatan) {
   $('#nik').val(nik);
   $('#nama').val(nama);
   $('#lokasi').val(lokasi);
   $('#divisi').val(divisi);
   $('#jabatan').val(jabatan);
   $('#display').hide();
}

Here is my input file:

<input type="text" class="form-control" id="nik">
<input type="text" class="form-control" id="nama">
<input type="text" class="form-control" id="lokasi">
<input type="text" class="form-control" id="divisi">
<input type="text" class="form-control" id="jabatan">

Your JS function fill should be :

function fill(id, value) {
   $('#'+id).val(value);
}

Because you already sending the id as the first argument and the value as the second.