Bagaimaa Caranya Mengisi Beberapa Textbox saat pilih Dropdown


(I Kurnia) #1

Halo agan2 semua,

Saya Newbie di php Yii2, Sekarang saya lagi buat aplikasi Inventory menggunakan Yii2framworks,

cuma saat ini saya stack ada kendala. Yang saya maksud seperti berikut.

  1. Saya buat sebuah Dropdown dari data tabel A (kode barang, nama barang) misalkan ditampilkan nama Barang.

  2. Saat Dropdown itu dipilih datanya akan mengambil data di tabel B (isinya kode barang, lokasi dan jumlah) berdasarkan kode barang yang dipilih di Dropdown tsb,

  3. Data yang diambil akan disimpan di 2 textbox, txtLokasi dan txtQuantity,

Pertanyaannya, bagaimana cara untuk membuat script langkah 2 dan 3.

Saya harap bantuan agan2 semua, Urgent pls.

Terima Kasih,

Iwan K

Ini contoh View nya

<div class="budgets-form">

&lt;div class=&quot;container-fluid&quot;&gt;


    &lt;?php


    &#036;form = ActiveForm::begin([


                'id' =&gt; 'new-form',


                'options' =&gt; ['class' =&gt; 'form-horizontal'],


                'method' =&gt; 'post',


    ]);


    ?&gt;


    &lt;div&gt;


        &lt;div class=&quot;form-group&quot;&gt;


            &lt;label class=&quot;control-label col-sm-2&quot; for=&quot;fld_no&quot;&gt;No. Circulait :&lt;/label&gt;


            &lt;div class=&quot;col-sm-10&quot;&gt;


                &lt;input type=&quot;text&quot; class=&quot;form-control&quot; id=&quot;fld_no&quot; name=&quot;fld_no&quot; readonly value=&quot; &lt;?php echo &#036;no ?&gt; &quot;&gt;


            &lt;/div&gt;


        &lt;/div&gt;


        &lt;div class=&quot;form-group&quot;&gt;


            &lt;label class=&quot;control-label col-sm-2&quot; for=&quot;fld_pos&quot;&gt;Posisi Baris :&lt;/label&gt;


            &lt;div class=&quot;col-sm-10&quot;&gt;


                &lt;input type=&quot;text&quot; class=&quot;form-control&quot; id=&quot;fld_pos&quot; placeholder=&quot;Posisi Baris&quot; readonly name=&quot;fld_pos&quot; value=&quot; &lt;?php echo &#036;pos ?&gt; &quot;&gt;


            &lt;/div&gt;


        &lt;/div&gt;


        &lt;div class=&quot;form-group&quot;&gt;


            &lt;label class=&quot;control-label col-sm-2&quot; for=&quot;fld_budget&quot;&gt;Budget :&lt;/label&gt;


            &lt;div class=&quot;col-sm-10&quot;&gt;


                &lt;?php


                echo Html::dropDownList('fld_budget', null, ArrayHelper::map(app&#092;models&#092;BudgetDetail::find()


                                        -&gt;where('fld_status' . &quot; = 'Active'&quot;)


                                        -&gt;all(), 'fld_no', 'fld_deskripsi'), [


                    'prompt' =&gt; Yii::t('app', 'Pilih Budget...'),


                    'onChange' =&gt; '&#036;.post( &quot;' . Yii::&#036;app-&gt;urlManager-&gt;createUrl([&quot;/circulait/getbdgt&quot;, 'id' =&gt; '']) . '&quot;,function(data){&#036;(&quot;#fld_bpos&quot;).val(data);})',


                    'id' =&gt; 'fld_budget',


                    'class' =&gt; 'dependent-input form-control',


                    'ajax' =&gt; [


                        'type' =&gt; 'POST',


                        'url' =&gt; Yii::&#036;app-&gt;urlManager-&gt;createUrl(['/circulait/getbdgt', 'id' =&gt; Yii::&#036;app-&gt;request-&gt;post()]),


                        'update' =&gt; '#fld_bpos',


                        'data' =&gt; ['fld_budget' =&gt; 'js:this.value'],


                        'success' =&gt; 'alert (&quot;ok&quot;);'


                    ]


                ]);


                ?&gt;


            &lt;/div&gt;


        &lt;/div&gt;


        &lt;div class=&quot;form-group&quot;&gt;


            &lt;label class=&quot;control-label col-sm-2&quot; for=&quot;fld_bpos&quot;&gt;Budget Line No. :&lt;/label&gt;


            &lt;div class=&quot;col-sm-10&quot;&gt;


                &lt;input type=&quot;text&quot; class=&quot;form-control&quot; id=&quot;fld_bpos&quot; placeholder=&quot;Budget Line No&quot; name=&quot;fld_bpos&quot;&gt;


            &lt;/div&gt;


        &lt;/div&gt;





        &lt;div class=&quot;form-group&quot;&gt;


            &lt;label class=&quot;control-label col-sm-2&quot; for=&quot;fld_jenis&quot;&gt;Jenis Budget :&lt;/label&gt;


            &lt;div class=&quot;col-sm-10&quot;&gt;


                &lt;?php


                echo Html::dropDownList('fld_jenis', null, ArrayHelper::map(&#036;tStatus, 'id', 'name'), [


                    'prompt' =&gt; Yii::t('app', 'Pilih Jenis...'),


                    'id' =&gt; 'fld_jenis',


                    'class' =&gt; 'dependent-input form-control',


                ]);


                ?&gt;


            &lt;/div&gt;


        &lt;/div&gt;


        &lt;div class=&quot;form-group&quot;&gt;


            &lt;label class=&quot;control-label col-sm-2&quot; for=&quot;fld_deskripsi&quot;&gt;Rincian :&lt;/label&gt;


            &lt;div class=&quot;col-sm-10&quot;&gt;


                &lt;input type=&quot;text&quot; class=&quot;form-control&quot; id=&quot;fld_deskripsi&quot; placeholder=&quot;Rincian&quot; name=&quot;fld_deskripsi&quot; &gt;


            &lt;/div&gt;


        &lt;/div&gt;


        &lt;div class=&quot;form-group&quot;&gt;


            &lt;label class=&quot;control-label col-sm-2&quot; for=&quot;fld_ket&quot;&gt;Keterangan :&lt;/label&gt;


            &lt;div class=&quot;col-sm-10&quot;&gt;


                &lt;input type=&quot;text&quot; class=&quot;form-control&quot; id=&quot;fld_ket&quot; placeholder=&quot;Keterangan&quot; name=&quot;fld_ket&quot;&gt;


            &lt;/div&gt;


        &lt;/div&gt;


        &lt;div class=&quot;form-group&quot;&gt;


            &lt;label class=&quot;control-label col-sm-2&quot; for=&quot;fld_curr&quot;&gt;Currency :&lt;/label&gt;


            &lt;div class=&quot;col-sm-10&quot;&gt;


                &lt;input type=&quot;text&quot; class=&quot;form-control&quot; id=&quot;fld_curr&quot; placeholder=&quot;Mata Uang&quot; name=&quot;fld_curr&quot; value=&quot;IDR&quot;&gt;


            &lt;/div&gt;


        &lt;/div&gt;


        &lt;div class=&quot;form-group&quot;&gt;


            &lt;label class=&quot;control-label col-sm-2&quot; for=&quot;fld_amount&quot;&gt;Amount :&lt;/label&gt;


            &lt;div class=&quot;col-sm-10&quot;&gt;


                &lt;input type=&quot;text&quot; class=&quot;form-control&quot; id=&quot;fld_amount&quot; placeholder=&quot;Jumlah&quot; name=&quot;fld_amount&quot; value=&quot;0&quot;&gt;


            &lt;/div&gt;


        &lt;/div&gt;


        &lt;div class=&quot;col-sm-12 form-group&quot;&gt;


            &lt;?=


            Html::submitButton('Simpan', [


                'content' =&gt; 'Button',

// ‘value’ => Url::to([‘trsmaster/simpan’]),

                'value' =&gt; 'ok',


                'class' =&gt; 'btn btn-success',


                'id' =&gt; 'create-btn',


                'name' =&gt; 'submitbtn'


            ])


            ?&gt;


        &lt;/div&gt;


    &lt;/div&gt;


    &lt;?php ActiveForm::end(); ?&gt;


&lt;/div&gt;

</div>


(I Kurnia) #2

Help me pls…!