Daftar dan Belajar Sekarang!

Chained dropdown ketiga eror dmna?

foto werich1
53 Kontribusi 2 Coto
1 minggu yang lalu
gan ane bikin 3 chained dropdown, 1 dan 2 masih bisa beralasi dan kebuka ketika provinsi dipilih tapi dari kab ke kecamatan langsung ga mau tampil kecamatanny itu gmna ya ?
<div class="container-fluid">

    <!-- Page Heading -->
    <h1 class="h3 mb-4 text-gray-800"><?= $title; ?></h1>


    <a href="" class="btn btn-primary mb-3" data-toggle="modal" data-target="#tambahSupply">Add Supplier</a>
    <br>
    <br>
    <table class="table">
        <thead>
            <tr>
                <th scope="col">#</th>
                <th scope="col">Cabang Supplier</th>
                <th scope="col">Email</th>
            </tr>
        </thead>
        <tbody>
            <?php $i = 1; ?>
            <?php foreach ($supplier as $s) : ?>
                <tr>
                    <th scope="row"><?= $i++; ?></th>
                    <td><?= $s['lokasi']; ?></td>
                    <td><?= $s['email']; ?></td>
                    <td><a href="<?= base_url(); ?>admin/edit_barang/<?= $s['id_sup']; ?>" class="badge badge-success">Edit</a>
                        <a href="<?= base_url(); ?>admin/hapus/<?= $s['id_sup']; ?>" class="badge badge-danger">Delete</a>
                    </td>

                </tr>
            <?php endforeach; ?>

        </tbody>
    </table>
    <div class="modal fade" id="tambahSupply" tabindex="-1" role="dialog" aria-labelledby="tambahSupply" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="tambahSupply">Order</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <?php echo form_open_multipart('admin/regis_supplier'); ?>


                <div class="modal-body">
                    <!-- Begin Page Content -->
                    <div class="form-group">

                        <label>Provinsi</label>
                        <select class="form-control" name="supplier" id="supplier">
                            <option value="">Please Select</option>
                            <?php
                            foreach ($wilayah as $s) {
                            ?>
                                <option <?php echo $provinsi_selected == $s->id ? 'selected="selected"' : '' ?> value="<?php echo $s->id ?>"><?php echo $s->provNama ?></option>
                            <?php
                            }
                            ?>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>Kota</label>
                        <select class="form-control" name="barang" id="barang">
                            <option value="">Please Select</option>
                            <?php
                            foreach ($wilayahb as $kot) {
                            ?>
                                <!--di sini kita tambahkan class berisi id provinsi-->
                                <option <?php echo $kota_selected == $kot->provinsi_id ? 'selected="selected"' : '' ?> class="<?php echo $kot->provinsi_id ?>" value="<?php echo $kot->id ?>"><?php echo $kot->KabNama ?></option>

                            <?php
                            }
                            ?>

                        </select>
                    </div>
                    <div class="form-group">
                        <label>Kecamatan</label>
                        <select class="form-control" name="camat" id="camat">
                            <option value="">Please Select</option>
                            <?php
                            foreach ($kecamatan as $kec) {
                            ?>
                                <!--di sini kita tambahkan class berisi id kota-->
                                <option <?php echo $kecamatan_selected == $kec->id ? 'selected="selected"' : '' ?> class="<?php echo $kec->kabupaten_id ?>" value="<?php echo $kec->id ?>"><?php echo $kec->kecNama ?></option>
                            <?php
                            }
                            ?>
                        </select>
                    </div>
                    <div class="form-group">
                        <input type="text" class="form-control" id="lokasi" name="lokasi" placeholder="Cabang Supplier">
                    </div>
                    <div class="form-group">
                        <input type="email" class="form-control" id="email" name="email" placeholder="Masukan Email Supplier">
                    </div>
                    <div class="form-group">
                        <input type="password" class="form-control" id="passowrd" name="password" placeholder="Masukan Passowrd">
                    </div>

                    <div class="form-group">
                        <input class="form-control" type="hidden" name="is_active" id="is_active" />
                    </div>
                    <div class="form-group">
                        <input class="form-control" type="hidden" name="sup_img" id="sup_img" />
                    </div>
                    <div class="form-group">
                        <input class="form-control" type="hidden" name="role_id" id="role_id" />
                    </div>

                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                    <button type="submit" class="btn btn-primary">Add Supplier</button>
                </div>
                </form>
            </div>
        </div>
        <script src="<?= base_url('assets/js/jquery-1.10.2.min.js') ?>"></script>
        <script src="<?= base_url('assets/js/jquery.chained.min.js') ?>"></script>
        <script>
            $("#barang").chained("#supplier"); // disini kita hubungkan kota dengan provinsi
            $("#camat").chained("#barang");

            // disini kita hubungkan kecamatan dengan kota
        </script>
        </script>
    </div>
</div>
</div>

Tag: codeigniter mysql php

✔ Forum ini sudah terjawab


Jawaban
foto Enma
3 Kontribusi 2 Coto
1 minggu yang lalu
Semoga ini bisa membantu
<?php
    //session_start();
    error_reporting(0);
    $judul_halaman = '3 CHAINED DROPDOWN';

    #koneksi ke database
    $con = mysqli_connect("localhost","root","ganti_dgn_password_anda","harviacode");
?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
        <meta name="description" content="">
        <meta name="author" content="">
        <link rel="icon" href="aset/favicon.ico">

        <title>DEMO PHP - <?= $judul_halaman ?></title>

        <!-- Bootstrap core CSS -->
        <link href="aset/css/bootstrap.min.css" rel="stylesheet">

        <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
        <link href="aset/css/ie10-viewport-bug-workaround.css" rel="stylesheet">

        <!-- Custom styles for this template -->
        <link href="aset/css/navbar-fixed-top.css" rel="stylesheet">
        <script src="aset/js/jquery.min.js"></script>
        <script src="aset/js/ie-emulation-modes-warning.js"></script>
    </head>

    <body>
        <!-- Fixed navbar -->
        <nav class="navbar navbar-inverse navbar-fixed-top">
            <div class="container">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" href="https://harviacode.com">HARVIACODE</a>
                </div>
                <div id="navbar" class="navbar-collapse collapse">
                    <ul class="nav navbar-nav">
                        <li class="active"><a href="https://demo-php.harviacode.com">DEMO PHP</a></li>
                    </ul>
                    <ul class="nav navbar-nav navbar-right">
                        <li class="active"><a href=""><?= $judul_halaman ?> <span class="sr-only">(current)</span></a></li>
                    </ul>
                </div><!--/.nav-collapse -->
            </div>
        </nav>

        <!-- Main Content -->
        <div class="container">
            <div class="col-md-12">
                <div class="panel panel-primary">
                    <div class="panel-heading"><b><?= $judul_halaman ?></b></div>
                    <div class="panel-body">
                        <div class="row">
                            <div class="col-md-12">

                                <div class="alert alert-info"><b>Mohon maaf karena keterbatasan sumber daya, kami membatasi jumlah data yang dimunculkan untuk masing-masing dropdown Kabupaten/ Kota dan Kecamatan.</b></div>

                                <form class="form-horizontal" method="post">

                                    <div class="form-group">
                                        <div class="col-sm-6">
                                            <!--provinsi-->
                                            <select id="provinsi" class="form-control" name="provinsi">
                                                <option value="">Please Select</option>
                                                <?php
                                                    $query = mysqli_query($con, "SELECT * FROM provinsi ORDER BY provinsi");
                                                    while ($row = mysqli_fetch_array($query)) { ?>

                                                    <option value="<?php echo $row['id_provinsi']; ?>">
                                                        <?php echo $row['provinsi']; ?>
                                                    </option>

                                                <?php } ?>
                                            </select>
                                        </div>

                                        <div class="col-sm-3">
                                            <!--kota-->
                                            <select id="kota" class="form-control" name="kota">
                                                <option value="">Please Select</option>
                                                <?php
                                                    $query = mysqli_query($con, "SELECT * FROM kota INNER JOIN provinsi ON kota.id_provinsi_fk = provinsi.id_provinsi ORDER BY nama_kota");
                                                    while ($row = mysqli_fetch_array($query)) { ?>

                                                    <option id="kota" class="<?php echo $row['id_provinsi']; ?>" value="<?php echo $row['id_kota']; ?>">
                                                        <?php echo $row['nama_kota']; ?>
                                                    </option>

                                                <?php } ?>
                                            </select>
                                        </div>
                                        <div class="col-sm-3">
                                            <!--kecamatan-->
                                            <select id="kecamatan" class="form-control" name="kecamatan">
                                                <option value="">Please Select</option>
                                                <?php
                                                    $query = mysqli_query($con, "SELECT * FROM kecamatan INNER JOIN kota ON kecamatan.id_kota_fk = kota.id_kota ORDER BY nama_kecamatan");
                                                    while ($row = mysqli_fetch_array($query)) { ?>

                                                    <option id="kecamatan" class="<?php echo $row['id_kota']; ?>" value="<?php echo $row['id_kecamatan']; ?>">
                                                        <?php echo $row['nama_kecamatan']; ?>
                                                    </option>

                                                <?php } ?>
                                            </select>
                                        </div>
                                    </div>   
                                </form>
                            </div>
                        </div>
                    </div>
                    <div class="panel-footer"><small>© <?= date('Y') ?> <a href="https://harviacode.com" target="_blank">Harviacode</a></small></div>
                </div>
            </div>
        </div>

        <!-- Bootstrap core JavaScript
        ================================================== -->
        <script src="aset/js/bootstrap.min.js"></script>
        <script src="aset/js/jquery-chained.min.js"></script>
        <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
        <script src="aset/js/ie10-viewport-bug-workaround.js"></script>
        <script>
            $(document).ready(function() {
                $("#kota").chained("#provinsi");
                $("#kecamatan").chained("#kota");
            });
        </script>
    </body>
</html>
answered icon
foto Enma
3 Kontribusi 2 Coto
1 minggu yang lalu
Semoga ini bisa membantu
<?php
    //session_start();
    error_reporting(0);
    $judul_halaman = '3 CHAINED DROPDOWN';

    #koneksi ke database
    $con = mysqli_connect("localhost","root","ganti_dgn_password_anda","harviacode");
?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
        <meta name="description" content="">
        <meta name="author" content="">
        <link rel="icon" href="aset/favicon.ico">

        <title>DEMO PHP - <?= $judul_halaman ?></title>

        <!-- Bootstrap core CSS -->
        <link href="aset/css/bootstrap.min.css" rel="stylesheet">

        <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
        <link href="aset/css/ie10-viewport-bug-workaround.css" rel="stylesheet">

        <!-- Custom styles for this template -->
        <link href="aset/css/navbar-fixed-top.css" rel="stylesheet">
        <script src="aset/js/jquery.min.js"></script>
        <script src="aset/js/ie-emulation-modes-warning.js"></script>
    </head>

    <body>
        <!-- Fixed navbar -->
        <nav class="navbar navbar-inverse navbar-fixed-top">
            <div class="container">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" href="https://harviacode.com">HARVIACODE</a>
                </div>
                <div id="navbar" class="navbar-collapse collapse">
                    <ul class="nav navbar-nav">
                        <li class="active"><a href="https://demo-php.harviacode.com">DEMO PHP</a></li>
                    </ul>
                    <ul class="nav navbar-nav navbar-right">
                        <li class="active"><a href=""><?= $judul_halaman ?> <span class="sr-only">(current)</span></a></li>
                    </ul>
                </div><!--/.nav-collapse -->
            </div>
        </nav>

        <!-- Main Content -->
        <div class="container">
            <div class="col-md-12">
                <div class="panel panel-primary">
                    <div class="panel-heading"><b><?= $judul_halaman ?></b></div>
                    <div class="panel-body">
                        <div class="row">
                            <div class="col-md-12">

                                <div class="alert alert-info"><b>Mohon maaf karena keterbatasan sumber daya, kami membatasi jumlah data yang dimunculkan untuk masing-masing dropdown Kabupaten/ Kota dan Kecamatan.</b></div>

                                <form class="form-horizontal" method="post">

                                    <div class="form-group">
                                        <div class="col-sm-6">
                                            <!--provinsi-->
                                            <select id="provinsi" class="form-control" name="provinsi">
                                                <option value="">Please Select</option>
                                                <?php
                                                    $query = mysqli_query($con, "SELECT * FROM provinsi ORDER BY provinsi");
                                                    while ($row = mysqli_fetch_array($query)) { ?>

                                                    <option value="<?php echo $row['id_provinsi']; ?>">
                                                        <?php echo $row['provinsi']; ?>
                                                    </option>

                                                <?php } ?>
                                            </select>
                                        </div>

                                        <div class="col-sm-3">
                                            <!--kota-->
                                            <select id="kota" class="form-control" name="kota">
                                                <option value="">Please Select</option>
                                                <?php
                                                    $query = mysqli_query($con, "SELECT * FROM kota INNER JOIN provinsi ON kota.id_provinsi_fk = provinsi.id_provinsi ORDER BY nama_kota");
                                                    while ($row = mysqli_fetch_array($query)) { ?>

                                                    <option id="kota" class="<?php echo $row['id_provinsi']; ?>" value="<?php echo $row['id_kota']; ?>">
                                                        <?php echo $row['nama_kota']; ?>
                                                    </option>

                                                <?php } ?>
                                            </select>
                                        </div>
                                        <div class="col-sm-3">
                                            <!--kecamatan-->
                                            <select id="kecamatan" class="form-control" name="kecamatan">
                                                <option value="">Please Select</option>
                                                <?php
                                                    $query = mysqli_query($con, "SELECT * FROM kecamatan INNER JOIN kota ON kecamatan.id_kota_fk = kota.id_kota ORDER BY nama_kecamatan");
                                                    while ($row = mysqli_fetch_array($query)) { ?>

                                                    <option id="kecamatan" class="<?php echo $row['id_kota']; ?>" value="<?php echo $row['id_kecamatan']; ?>">
                                                        <?php echo $row['nama_kecamatan']; ?>
                                                    </option>

                                                <?php } ?>
                                            </select>
                                        </div>
                                    </div>   
                                </form>
                            </div>
                        </div>
                    </div>
                    <div class="panel-footer"><small>© <?= date('Y') ?> <a href="https://harviacode.com" target="_blank">Harviacode</a></small></div>
                </div>
            </div>
        </div>

        <!-- Bootstrap core JavaScript
        ================================================== -->
        <script src="aset/js/bootstrap.min.js"></script>
        <script src="aset/js/jquery-chained.min.js"></script>
        <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
        <script src="aset/js/ie10-viewport-bug-workaround.js"></script>
        <script>
            $(document).ready(function() {
                $("#kota").chained("#provinsi");
                $("#kecamatan").chained("#kota");
            });
        </script>
    </body>
</html>


Login untuk diksusi di forum sekolah koding