[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
<?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
source
share