Menangkap data dari Select Dropdown

Bagaimana cara menangkap data dari pilihan dropdown agar tampil di semua inputan tabel,

saya sudah mencoba tetapi hanya menampilkan 1 data pada inputan

<?php
                $result = mysqli_query($db, "SELECT * from tb_matkul ORDER BY dosen ASC");
                $jsArray = "var prdName = new Array();";
                echo 'Nama Dosen <font color="red">*</font> :

                <select class="form-control" onchange="changeValue(this.value)" required="">';

               echo '<option value="">- Pilih -</option>';

               while ($row = mysqli_fetch_array($result)) {

                 echo '<option value="' . $row['dosen'] . '">' . $row['dosen'] . '&nbsp;'.' | '.'&nbsp;' . $row['matkul'] . '&nbsp;'.' | '.'&nbsp;' . '&nbsp;' . 'semester' . $row['semester'] . '&nbsp;'.' | '.'&nbsp;' . 'periode' . '&nbsp;' . $row['periode'] . '</option>';

                 $jsArray .= "prdName['" . $row['dosen'] . "'] = {matkul:'" . addslashes($row['matkul']) . "',semester:'".addslashes($row['semester']) . "',periode:'".addslashes($row['periode']) . "',dosen:'".addslashes($row['dosen'])."'};";
                }
                echo '</select>';
<?php
                $result = mysqli_query($db, "SELECT * from tb_matkul ORDER BY dosen ASC");
                $jsArray = "var prdName = new Array();";
                echo 'Nama Dosen <font color="red">*</font> :

                <select class="form-control" onchange="changeValue(this.value)" required="">';

               echo '<option value="">- Pilih -</option>';

               while ($row = mysqli_fetch_array($result)) {

                 echo '<option value="' . $row['dosen'] . '">' . $row['dosen'] . '&nbsp;'.' | '.'&nbsp;' . $row['matkul'] . '&nbsp;'.' | '.'&nbsp;' . '&nbsp;' . 'semester' . $row['semester'] . '&nbsp;'.' | '.'&nbsp;' . 'periode' . '&nbsp;' . $row['periode'] . '</option>';

                 $jsArray .= "prdName['" . $row['dosen'] . "'] = {matkul:'" . addslashes($row['matkul']) . "',semester:'".addslashes($row['semester']) . "',periode:'".addslashes($row['periode']) . "',dosen:'".addslashes($row['dosen'])."'};";
                }
                echo '</select>';
<?php
                $result = mysqli_query($db, "SELECT * from tb_matkul ORDER BY dosen ASC");
                $jsArray = "var prdName = new Array();";
                echo 'Nama Dosen <font color="red">*</font> :

                <select class="form-control" onchange="changeValue(this.value)" required="">';

               echo '<option value="">- Pilih -</option>';

               while ($row = mysqli_fetch_array($result)) {

                 echo '<option value="' . $row['dosen'] . '">' . $row['dosen'] . '&nbsp;'.' | '.'&nbsp;' . $row['matkul'] . '&nbsp;'.' | '.'&nbsp;' . '&nbsp;' . 'semester' . $row['semester'] . '&nbsp;'.' | '.'&nbsp;' . 'periode' . '&nbsp;' . $row['periode'] . '</option>';

                 $jsArray .= "prdName['" . $row['dosen'] . "'] = {matkul:'" . addslashes($row['matkul']) . "',semester:'".addslashes($row['semester']) . "',periode:'".addslashes($row['periode']) . "',dosen:'".addslashes($row['dosen'])."'};";
                }
                echo '</select>';
?>
<script type="text/javascript">
                <?php echo $jsArray; ?>
                function changeValue(id){
                document.getElementById('prd_matkul').value = prdName[id].matkul;
                document.getElementById('prd_dosen').value = prdName[id].dosen;
                document.getElementById('prd_semester').value = prdName[id].semester;
                document.getElementById('prd_dosen').value = prdName[id].dosen;
                };
                </script>

<table id="example2" class="table table-bordered table-hover">
            <thead>
                <tr>
                    <th>No</th>
                    <th>Jenis / Kategori</th>
                    <th>Pertanyaan</th>
                    <th>Bobot</th>
                </tr>
            </thead>
            <?php
            if (isset($_GET['jenis_pertanyaan'])) {
                $jenis_pertanyaan=trim($_GET['jenis_pertanyaan']);
                $tamPeg=mysqli_query($db, "SELECT * FROM tb_pertanyaan WHERE jenis_pertanyaan='$jenis_pertanyaan' ORDER BY kd_pertanyaan ASC");
                $no=0;
                while ($tpeg = mysqli_fetch_array($tamPeg)) {
                $no++;
                ?>
            <tbody>
                <tr>
                    <td><input type="text" name="nama_dosen[]" id="prd_dosen"></td>
                    <td><input type="text" name="matkul[]" id="prd_matkul"></td>
                    <td><input type="text" name="semester[]" value="1" hidden=""></td>
                    <td><?php echo $no;?></td>
                    <td><input type="text" hidden="" name="jenis_pertanyaan[]" value="<?php echo $tpeg['jenis_pertanyaan'];?>">
                        <?php echo $tpeg['jenis_pertanyaan'];?></td>
                    <td><input type="text" hidden="" name="pertanyaan[]" value="<?php echo $tpeg['pertanyaan'];?>">
                        <?php echo $tpeg['pertanyaan'];?></td>
                    <td>
                    <select name="bobot[]" class="form-control" required="">
                        <option value="">- Pilih -</option>
                    <?php
                    $sql_bobot = mysqli_query($db, "SELECT * from tb_bobot") or die ($db->error);
                    while($data_bobot = mysqli_fetch_array($sql_bobot)) {
                    echo '<option value="'.$data_bobot['bobot'].'">'.$data_bobot['bobot'].'</option>';
                    ?>
                    <?php
                    }
                    ?>
                    </select></td>
                </tr>            </tbody>

p1.jpg

Diharapkan ketika kita memilih dari dropdown maka data di inputan tabel merekam sesuai jumlah keseluruhan tabel , pada gambar yaitu berjumlah = 6

avatar taufikustanto
@taufikustanto

14 Kontribusi 0 Poin

Diperbarui 2 tahun yang lalu

Belum ada Jawaban. Jadi yang pertama Jawaban

Login untuk ikut Jawaban