php - Cannot update textfield based on dropdown list Yii -
i have 3 dependent dropdowns, , textfield being dependent last dropdown. if 1 of value in last dropdown, want textfield value dynamically changes based on selected value (it's same database table).
this view of third dropdown:
<div class="row" id="id_subkeg"> <?php echo $form->labelex($model, 'id_subkeg'); ?> <?php echo $form->dropdownlist($model, 'id_subkeg', array(), array( 'style' => 'width: 100%', 'ajax' => array( 'type' => 'post', 'url' => ccontroller::createurl('dynamicsatuan'), 'update' => '#' . chtml::activeid($model, 'satuan'), //'update'=>'#seksi', 'data' => array('id_subkeg' => 'js:this.value'), ) ) ); ?> <?php echo $form->error($model, 'id_subkeg'); ?> </div>
this textfield view:
<div class="row" id="satuan"> <?php echo $form->labelex($model, 'satuan'); ?> <p class="hint" style="font-size: 80%">contoh: dokumen.</p> <?php echo $form->textfield($model, 'satuan', array('style' => 'width: 98%;', 'readonly' => false)); ?> <?php echo $form->error($model, 'satuan'); ?> </div>
and action in controller:
public function actiondynamicsatuan() { //$data = subkegiatan::model()->findbypk($_post['id_subkeg']); $data = subkegiatan::model()->findbypk('id_subkeg=:id_subkeg', array(':id_subkeg' => (int) $_post['id_subkeg'])); echo $data->satuan; }
but it's not been working days. don't know part i've missed. guess dropdown dependent dropdown 1 above it. must have missed @ part.
any highly appreciated.
update: after days of searching, got it:
public function actiondynamicsatuan() { $param_country = (int) $_post['id_subkeg']; $maxordernumber = yii::app()->db->createcommand() ->select('satuan') ->from('subkegiatan') ->where('id_subkeg = ' . $param_country) ->queryscalar(); echo '<b>satuan: '. $maxordernumber.'</b>'; //echo chtml::tag('input', array('type' => 'text', 'value' => $maxordernumber)); }
instead of update, use success callback:
echo $form->dropdownlist($model, 'id_subkeg', array(), array( 'style' => 'width: 100%', 'ajax' => array( 'type' => 'post', 'url' => ccontroller::createurl('dynamicsatuan'), 'data' => array('id_subkeg' => 'js:this.value'), 'success'=> 'function(data) { $("#your_id_here").empty(); $("#your_id_here").append(data); }' ) ) );
Comments
Post a Comment