Saya ingin menampilkan data dari database di textbox melalui combobox

Saya kan ingin menampilkan data secara otomatis di textbox menggunakan autofill tapi masalahnya saat ingin memasukkan di baris kedua tidak terjadi apa-apa dikolom baris kedua malah kolom-kolom dibaris pertama terganti dengan kolom pilihan di baris kedua.

<!DOCTYPE html>
<html>
 <head>
  <title>-----</title>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

 </head>
 <body>
  <br /><br />
  <div class="container">
   <br />
   <h2 align="center">Multiple Inline Insert</h2>
   <br />
   <div class="data">
      <div class="col-lg-6 col-lg-offset-3">
          <form action="index.php" method="post">
              <div class="form-group">
                  <label for ="count_add"> Banyak Tabel</label>
                  <input type="text" name="count_add" id="count_add" maxlength="2" pattern="[0-9]+" class="form-control" required>
              </div>
              <div class="form-group pull-right">
                  <input type="submit" name="generate" value="generate" class="btn btn-success">
              </div>
          </form>
      </div>
  </div>
  <div class="data">
      <div class="col-lg-20">
          <form action="save.php" method="post">
              <input type="hidden" name="total" value="<?=@$_POST['count_add']?>">
              <table class="table">
                  <tr>
                      <th>No</th>
                      <th>I Melaksanakan pendidikan dan pengajaran bagi mahasiswa S1, S2 dan S3 meliputi</th>
                      <th>Nilai</th>
                      <th>AK</th>
                      <th>Kuant</th>
                      <th>Output</th>
                      <th>Kual/Mutu</th>
                      <th colspan="2"><center>Waktu</center></th>
                      <th>Biaya</th>
                  </tr>
                  <?php

                  for ($i=1; $i<=$_POST['count_add']; $i++) { ?>
                    <tr>
                        <td><?=$i?></td>
                        <td>
                            <select id="i_skp" name="nama-<?=$i?>" onchange="changeValue(this.value)" class="form-control" required>
                              <option disabled="" selected="">Pilih</option>
                              <?php
                                include "koneksi.php";
                                $sql=mysql_query("SELECT * FROM tb_i");
                                $jsArray = "var prdName = new Array();\n";
                                while ($data=mysql_fetch_array($sql)) {

                                  echo '<option value="'.$data['i_skp'].'">'.$data['i_skp'].'</option> ';
                                  $jsArray .= "prdName['" . $data['i_skp'] . "'] = {nilai:'" . addslashes($data['nilai']) . "',
                                                                                    ak:'".addslashes($data['ak'])."',
                                                                                    kuant:'".addslashes($data['kuant'])."',
                                                                                    output:'".addslashes($data['output'])."',
                                                                                    mutu:'".addslashes($data['mutu'])."',
                                                                                    waktu:'".addslashes($data['waktu'])."',
                                                                                    bln_thn:'".addslashes($data['bln_thn'])."',
                                                                                    biaya:'".addslashes($data['biaya'])."',
                                                                                    };\n";
                                }
                              ?>
                            </select>
                        </td>
                        <td>
                            <input type="text" name="nama-<?=$i?>" id="nilai" class="form-control" required>
                        </td>
                        <td>
                            <input type="text" name="nama-<?=$i?>" id="ak" class="form-control" required>
                        </td>
                        <td>
                            <input type="text" name="nama-<?=$i?>" id="kuant" class="form-control" required>
                        </td>
                        <td>
                            <input type="text" name="nama-<?=$i?>" id="output" class="form-control" required>
                        </td>
                        <td>
                            <input type="text" name="nama-<?=$i?>" id="mutu" class="form-control" required>
                        </td>
                        <td>
                            <input type="text" name="nama-<?=$i?>" id="waktu" class="form-control" required>
                        </td>
                        <td>
                            <input type="text" name="nama-<?=$i?>" id="bln_thn" class="form-control" required>
                        </td>
                        <td>
                            <input type="text" name="nama-<?=$i?>" id="biaya" class="form-control" required>
                        </td>
                    </tr>
                  <?php
                    }
                  ?>
              </table>
              <div class="form-group pull-right">
                    <input type="submit" name="add" value="Simpan Semua" class="btn btn-success">
              </div>
          </form>
       </div>
  </div>
  <script type="text/javascript">
    <?php echo $jsArray; ?>
    function changeValue(x){
    document.getElementById('nilai').value = prdName[x].nilai;
    document.getElementById('ak').value = prdName[x].ak;
    document.getElementById('kuant').value = prdName[x].kuant;
    document.getElementById('output').value = prdName[x].output;
    document.getElementById('mutu').value = prdName[x].mutu;
    document.getElementById('waktu').value = prdName[x].waktu;
    document.getElementById('bln_thn').value = prdName[x].bln_thn;
    document.getElementById('biaya').value = prdName[x].biaya;
    };

    </script>
 </body>
</html>

Mohon solusinya..

Terima kasih..

avatar toster000
@toster000

1 Kontribusi 0 Poin

Dipost 4 tahun yang lalu

Belum ada Jawaban. Jadi yang pertama Jawaban

Login untuk ikut Jawaban