[SOLVED :: Updated the CODE ] There is a drop down list and a text filed. Text filed will be filled per drop down selection by Ajax in Yii form. And I need to pass parameter to controller via Ajax URL. It is working when I pass static parameter via URL. But failed to 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 parameter from Ajax URl "array('pp_store'=>'333')" then it is working well. But I need to send data dynamically.
[SOLVED :: Updated the CODE ] Enjoy Coding