<div class="modal fade" id="alamat_detail" tabindex="-1" role="dialog" aria-labelledby="alamat_detailTitle" aria-hidden="true">
    <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="alamat_detailTitle">
                    Tambah Anggota Koperasi
                </h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body" id="detail_body_alamat">
                <?php echo form_open_multipart('marketing/kegiatan/pengajuan_pinjaman/crud'); ?>
                <input type="hidden" name="<?= $this->security->get_csrf_token_name(); ?>" value="<?= $this->security->get_csrf_hash(); ?>" style="display: none">
                <div class="form-group">
                    <label>Nomor Induk Kependudukan</label>
                    <input type="text" class="form-control" readonly id="nik_anggota" name="nik_anggota" placeholder="Anggota ID" required>
                </div>
                <div class="form-group">
                    <label>Alamat Lengkap</label>
                    <textarea class="form-control" name="alamat_lengkap" id="alamat_lengkap" cols="30" rows="2" placeholder="Mis. Jalan, Sekolah, Perumahan, Dst" required></textarea>
                </div>
                <div class="form-group">
                    <label for="">Pilih Kabupaten / Kota</label>
                    <select class="form-control" id="kota_kabupaten" name="kota_kabupaten" required>
                        <option value="PILIH">Pilih Kabupaten / Kota</option>
                        <?php foreach ($data_kota as $Data_kota) : ?>
                            <option value="<?= $Data_kota->kot_kab ?>"><?= $Data_kota->kot_kab ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
                <div class="form-row mb-4">
                    <div class="col-6">
                        <label for="">Pilih Kecamatan</label>
                        <select class="form-control" id="kecamatan_baru" name="kecamatan_baru" required>
                        </select>
                    </div>
                    <div class="col-6">
                        <label for="">Pilih Desa</label>
                        <select class="form-control" id="dk_ds" name="dk_ds" required>
                        </select>
                    </div>
                </div>
                <div class="form-row mb-4">
                    <div class="col">
                        <label for="">RT</label>
                        <select class="form-control" id="nm_rt" name="nm_rt" required>
                            <option value="001">001</option>
                            <option value="002">002</option>
                            <option value="003">003</option>
                            <option value="004">004</option>
                            <option value="005">005</option>
                            <option value="006">006</option>
                            <option value="007">007</option>
                            <option value="008">008</option>
                            <option value="009">009</option>
                            <option value="010">010</option>
                            <option value="011">011</option>
                            <option value="012">012</option>
                            <option value="013">013</option>
                            <option value="014">014</option>
                            <option value="015">015</option>
                            <option value="016">016</option>
                            <option value="017">017</option>
                            <option value="018">018</option>
                            <option value="019">019</option>
                            <option value="020">020</option>
                        </select>
                    </div>
                    <div class="col">
                        <label for="">RW</label>
                        <select class="form-control" id="nm_rw" name="nm_rw" required>
                            <option value="001">001</option>
                            <option value="002">002</option>
                            <option value="003">003</option>
                            <option value="004">004</option>
                            <option value="005">005</option>
                            <option value="006">006</option>
                            <option value="007">007</option>
                            <option value="008">008</option>
                            <option value="009">009</option>
                            <option value="010">010</option>
                            <option value="011">011</option>
                            <option value="012">012</option>
                            <option value="013">013</option>
                            <option value="014">014</option>
                            <option value="015">015</option>
                            <option value="016">016</option>
                            <option value="017">017</option>
                            <option value="018">018</option>
                            <option value="019">019</option>
                            <option value="020">020</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-outline-primary" data-dismiss="modal">
                    Close
                </button>
                <button type="submit" id="ubahDetailAlamat" name="ubahDetailAlamat" class="btn btn-primary">Simpan</button>
            </div>
            <?php echo form_close(); ?>
        </div>
    </div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type="text/javascript">
    $(document).on("click", "#detail_alamat", function() {
        var anggota_kota = $(this).data('anggota_kota');
        var nik = $(this).data('nik');
        var alamat_lengkap = $(this).data('alamat_lengkap');
        var nm_rt = $(this).data('nm_rt');
        var nm_rw = $(this).data('nm_rw');
        var nm_desa = $(this).data('nm_desa');
        var nm_kec = $(this).data('nm_kec');
        var kot_kab = $(this).data('kot_kab');
        var opt_kec = '<option value="' + nm_kec + '">' + nm_kec + '</option>';
        var opt_des = '<option value="' + nm_desa + '">' + nm_desa + '</option>';
        $(".modal-body#detail_body_alamat #nik_anggota").val(nik);
        $(".modal-body#detail_body_alamat #alamat_lengkap").val(alamat_lengkap);
        $(".modal-body#detail_body_alamat #nm_rt").val(nm_rt);
        $(".modal-body#detail_body_alamat #nm_rw").val(nm_rw);
        $(".modal-body#detail_body_alamat #kota_kabupaten").val(kot_kab);
        $(".modal-body#detail_body_alamat #kecamatan_baru").append(opt_kec);
        $(".modal-body#detail_body_alamat #dk_ds").append(opt_des);
    })
</script>
<!-- Script_alamat Baru -->
<script type="text/javascript">
    $('#kota_kabupaten').change(function() {
        var nm_kot_kab = $(this).val();
        $.ajax({
            type: 'POST',
            url: '<?= base_url('marketing/kot_kab') ?>',
            data: 'nm_kot_kab=' + nm_kot_kab,
            success: function(response) {
                $('#kecamatan_baru').html(response);
            }
        });
    });

    $('#kecamatan_baru').change(function() {
        var nm_kecamatan = $(this).val();
        $.ajax({
            type: 'POST',
            url: '<?= base_url('marketing/kecamatan') ?>',
            data: 'nm_kecamatan=' + nm_kecamatan,
            success: function(response) {
                $('#dk_ds').html(response);
            }
        });
    });
</script>