Ajax Dependable texfiled with dropdown in Yii not working

[SOLVED :: Updated CODE] . Drop-down list and text box. The submitted text will be filled in for one picture from Ajax in the form of Yii. And I need to pass the parameter to the controller via the Ajax URL. It works when I pass a static parameter through a URL. But could not get the dynamic parameter.

My form ::

    <div class="row">
    <?php echo $form->labelEx($model,'pp_store'); ?>
    <?php // echo $form->dropDownlist($model,'pp_store', CHtml::listData(Branchmaster::model()->findAll(), 'cm_branch', 'cm_branch')); ?>
    <?php $storeArray = CHtml::listData(Branchmaster::model()->findAll(),'cm_branch','cm_branch');
       echo $form->dropDownList($model,'pp_store', $storeArray, 
                      array(
                            'empty'=>"Select Warehouse",
                            'ajax' => array(
                                'type'=>'POST',
                                'url'=>CController::createUrl('purchaseordhd/GetCurrency' ),
                                'update' => '#currencyid',  
                                'data'=>array('store'=>'js:this.value',),   
                                'success'=> 'function(data) {$("#currencyid").empty();
                                $("#currencyid").val(data);
                                } ', 
                      ),

        )); ?>
    <?php echo $form->error($model,'pp_store'); ?>
</div>

<div class="row">
    <?php echo $form->labelEx($model,'pp_currency'); ?>
    <?php echo $form->textField($model,'pp_currency', array('id'=>'currencyid', 'readonly'=> true)); ?>
    <?php echo $form->error($model,'pp_currency'); ?>
</div>

My controller ::

        public function actionGetCurrency()
    {
        $q = $_POST['store'];

        $sql = "SELECT cm_currency as value FROM cm_branchmaster WHERE cm_branch= '$q' ";
        $command = Yii::app()->db->createCommand($sql);
        $result= $command->queryScalar(); 
        echo $result;

    }

When I send a parameter from an Ajax URl array ('pp_store' => '333'), then it works well. But I need to send data dynamically.

[SOLVED :: Updated CODE] Enjoy coding

+4
source share
1

. POST.

http://www.yiiframework.com/wiki/24/creating-a-dependent-dropdown/

echo CHtml::dropDownList('country_id','', array(1=>'USA',2=>'France',3=>'Japan'),
array(
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl('currentController/dynamiccities'), //url to call.
//Style: CController::createUrl('currentController/methodToCall')
'update'=>'#city_id', //selector to update
//'data'=>'js:javascript statement' 
//leave out the data key to pass all form values through
))); 

//empty since it will be filled by the other dropdown
echo CHtml::dropDownList('city_id','', array());

, 'data'=>'js:javascript statement'.

0

All Articles