hello…
i want to make a combo box when I select the advertiser, the product combo box contents will change (according to the selected combo_box_advertiser).
and textfield job_id will changed to the name of the advertiser selected
I’ve tried using JSON but not successful
help me please…
my code:
Batch /_form
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'batch-form',
'enableAjaxValidation'=>true,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'jobs_id'); ?>
<?php echo $form->textField($model,'jobs_id',array('size'=>50,'maxlength'=>50)); ?>
<?php echo $form->error($model,'jobs_id'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'id_advertiser'); ?>
<?php echo $form->dropDownList($model,'id_advertiser',CHtml::listData(Advertiser::model()->findAll('deleted IS NULL or deleted <> :deleted',array(':deleted'=>1)), 'id', 'name'),
array('empty'=>'--Please Choose One--'),
array(
'type'=>'POST',
'dataType'=>'json',
'data'=>array('id_advertiser'=>'js:$(\'#Batch_id_advertiser\').val()'),//-->is this correct??
'url'=>CController::createUrl('dodo'),
'success'=>'function(data) {
$("#Batch_id_product_category").html(data.dropdownA);
$("#Batch_jobs_id").html(data.id_advertiser);
}',
)
); ?>
<?php echo $form->error($model,'id_advertiser'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'id_product_category'); ?>
<?php echo $form->dropDownList($model,'id_product_category',array()); ?>
<?php echo $form->error($model,'id_product_category'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
BatchController:
.
public function actionDodo()
{
$id_advertiser = Yii::app()->request->getParam('id_advertiser');
$data=AdvertiserCategory::model()->findAll('id_advertiser=:parent_id',
array(':parent_id'=>(int)$id_advertiser));
$data=CHtml::listData($data,'id_product_category','id_product_category');
foreach($data as $value=>$id_product_category)
{
$dropDownA .= CHtml::tag('option', array('value'=>$value),CHtml::encode($id_product_category),true);
}
// return data (JSON formatted)
echo CJSON::encode(array(
'dropDownA'=>$dropDownA,
'id_advertiser'=>$id_advertiser,
)); Yii::app()->end();
}
}