menyimpan data dari combobox & textbox

Haloo, salam kenal, sy masih baru di CI, dan ada permasalahan saat menyimpan data dari combobox dan textbox, mungkin disini ada yang bisa bantu ?

ini kode di view sy:

<form role="form" action="<?php echo site_url('c_home/proses_transin_seragam') ?>" method="post">
                    <div class="form-group form-inline">
                            <script type="text/javascript">
                                function addText(){
                                    var x = document.getElementById("dd_srgm");
                                    var y = document.getElementById("nm_srgm");
                                    getSrgm = x.value;
                                    y.value = getSrgm;
                                }
                            </script>
                        <label style="width:15%">Kode barang</label>
                        <label> : </label>
                        <select class="form-control" name="dd_srgm" id="dd_srgm" onchange="javascript: addText();" required>
                            <option></option>
                            <?php foreach ($dd_seragam as $kd_srgm) { ?>
                                <option value="<?php echo $kd_srgm->nama_brg ?>"><?php echo $kd_srgm->kd_brg ?></option>
                            <?php } ?>
                        </select>
                    </div>
                    <div class="form-group form-inline">
                        <label style="width:15%">Nama barang</label>
                        <label> : </label>
                        <input class="form-control" type="text" name="nm_srgm" id="nm_srgm" style="width:35%">
                        <input class="form-control" style="width:8%" name="qty_in" placeholder="Qty">

                    </div>

ini controlernya :

class c_home extends ci_controller
{
	public function __construct()
	{
		parent::__construct();
		$this->load->model('m_home');
	}

	public function index()
	{
		$data['dd_seragam'] = $this->m_home->dropdown_seragam();
		$this->load->view('v_home', $data);
	}

	public function proses_transin_seragam()
	{
		$kd_brg = $this->input->post('dd_srgm');
		$nama_brg = $this->input->post('nm_srgm');
		$jumlah_brg = $this->input->post('qty_in');
		$satuan = $this->input->post('satuan');
		$tanggal_in = $this->input->post('tgl_masuk');
		$ket_in = $this->input->post('ket_masuk');

		$data = array(
			'kd_brg'=>$kd_brg,
			'nama_brg'=>$nama_brg,
			'jumlah_brg'=>$jumlah_brg,
			'satuan'=>$satuan,
			'tanggal_in'=>$tanggal_in,
			'ket_in'=>$ket_in
			);

			$this->m_home->tambah_transin_seragam($data,'tb_transin_seragam');
			redirect('c_home');
	}

ini tampilannya :

ini yang masuk di table :

di kolom 'kd_brg' yg masuk malah nama barang, bukan kode barang.

tolong bantuannya supaya yg masing-masing kolom di tablenya terisi sesuai isian di form nya. terimakasih sebelumnya...

avatar alfiardhan
@alfiardhan

4 Kontribusi 0 Poin

Diperbarui 3 tahun yang lalu

9 Jawaban:

option value nya nampilin nama barang

<?php foreach ($dd_seragam as $kd_srgm) { ?>
                                <option value="<?php echo $kd_srgm->nama_brg ?>"><?php echo $kd_srgm->kd_brg ?></option>
                            <?php } ?>

ganti kode di option value nya

<?php foreach ($dd_seragam as $kd_srgm) { ?>
                                <option value="<?php echo $kd_srgm->kd_brg ?>"><?php echo $kd_srgm->kd_brg ?></option>
                            <?php } ?>

avatar imamriyadi
@imamriyadi

26 Kontribusi 4 Poin

Dipost 8 tahun yang lalu

itu sudah saya coba mas, kalau option valuenya sy rubah jadi kd_brg, nanti di textbox nya yang muncul bukan nama barang tapi kode barang juga, sperti ini :

avatar alfiardhan
@alfiardhan

4 Kontribusi 0 Poin

Dipost 8 tahun yang lalu

Dibuat gini aja gan

<?php foreach ($dd_seragam as $kd_srgm) { ?>
  <option value="<?php echo $kd_srgm->kd_brg ?>"><?php echo $kd_srgm->nama_brg ?></option>
<?php } ?>

avatar ackerz
@ackerz

54 Kontribusi 31 Poin

Dipost 8 tahun yang lalu

kalau itu malah jadi kebalik mas ackerz, jadi gini :

soalnya textbox saya ini otomatis ke isi sesuai pilihan dari comboboxnya mas, ini kode js nya :

<script type="text/javascript">
                                function addText(){
                                    var x = document.getElementById("dd_srgm");
                                    var y = document.getElementById("nm_srgm");
                                    getSrgm = x.value;
                                    y.value = getSrgm;
                                }
                            </script>

textbox nya ngambil value dari option combobox, makanya saya pakai kode yg sebelumnya :

<?php foreach ($dd_seragam as $kd_srgm) { ?>
                                <option value="<?php echo $kd_srgm->nama_brg ?>"><?php echo $kd_srgm->kd_brg ?></option>
<?php } ?>

avatar alfiardhan
@alfiardhan

4 Kontribusi 0 Poin

Dipost 8 tahun yang lalu

Jawaban Terpilih

dibuat gini aja gan

<script type="text/javascript">
function addText(){
var x = document.getElementById("dd_srgm");
var y = document.getElementById("nm_srgm");
getSrgm = x.value;
res = getSrgm.split("|");
y.value = res[1];
}
</script>

<?php foreach ($dd_seragam as $kd_srgm) { ?>
  <option value="<?php echo $kd_srgm->kd_brg ?>|<?php echo $kd_srgm->nama_brg ?>"><?php echo $kd_srgm->kd_brg ?></option>
<?php } ?>

tapi entar di prosesnya agan juga harus split valuenya

        public function proses_transin_seragam()
	{
                $split = explode('|', $this->input->post('dd_srgm'));
		$kd_brg = $split[0];
		$nama_brg = $this->input->post('nm_srgm');
		$jumlah_brg = $this->input->post('qty_in');
		$satuan = $this->input->post('satuan');
		$tanggal_in = $this->input->post('tgl_masuk');
		$ket_in = $this->input->post('ket_masuk');

		$data = array(
			'kd_brg'=>$kd_brg,
			'nama_brg'=>$nama_brg,
			'jumlah_brg'=>$jumlah_brg,
			'satuan'=>$satuan,
			'tanggal_in'=>$tanggal_in,
			'ket_in'=>$ket_in
			);

			$this->m_home->tambah_transin_seragam($data,'tb_transin_seragam');
			redirect('c_home');
	}

avatar ackerz
@ackerz

54 Kontribusi 31 Poin

Dipost 8 tahun yang lalu

wah mas ackerz, caranya berhasil

data kode barang sudah bisa masuk ke kolom kd_brg.

trimakasih bantuannya ya.

avatar alfiardhan
@alfiardhan

4 Kontribusi 0 Poin

Dipost 8 tahun yang lalu

@alfiardhan: sama-sama, senang bisa membantu juga, gan :D /

avatar ackerz
@ackerz

54 Kontribusi 31 Poin

Dipost 8 tahun yang lalu

@alfiardhan : boleh minta coding auto texboxtnya gan, masih meraba di ci mohon bantuan dari para suhu

avatar inu70
@inu70

3 Kontribusi 0 Poin

Dipost 6 tahun yang lalu

<div>&lt;div class="form-group"&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;label for="sel1"&gt;Pilih Kecamatan:&lt;/label&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;select class="form-control" name="kecamatan"&nbsp; id="kecamatan"&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;?php<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; include "koneksi.php";<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Perintah sql untuk menampilkan semua data pada tabel&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $sql="select * from kecamatan";<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $hasil=mysqli_query($koneksi,$sql);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while ($r = mysqli_fetch_array($hasil)) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ?&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;option&nbsp; value="&lt;?php echo $r['id_kecamatan'];?&gt;"&gt;&lt;?php echo $r['nama_kecamatan'];?&gt;&lt;/option&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;?php<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ?&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/select&gt;<br> <br> <br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;div class="form-group"&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;label for="sel1"&gt;Pilih Desa:&lt;/label&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;select class="form-control" name="desa"&nbsp; id="desa"&gt;<br> <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/select&gt;<br> <br> <br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;<br>Tolong kak... masuk ke database tidak sesuai dengan datanya tapi masuk nomor idnya...</div>

avatar widodododo
@widodododo

1 Kontribusi 0 Poin

Dipost 3 tahun yang lalu

Login untuk ikut Jawaban