my form
my controller function
i dont know why my ajax is not updating dropdownlist category any one can hep me plese, or to help me find the bug thanks in advance.
Reinhard navarro [Nhexia]
<style type="text/css"> .alert{ width: 500px;} #hide{ visibility: hidden;} </style> <?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm',array( 'id'=>'cash-advance-form', 'enableAjaxValidation'=>false, )); ?> <?php $this->widget('bootstrap.widgets.TbLabel', array( 'type'=>'info', // 'success', 'warning', 'important', 'info' or 'inverse' 'label'=>'Fields with * are required', 'htmlOptions'=>array('style'=>'padding:5px;') )); ?> <br/><br/> <?php $user = Yii::app()->user->name ;?> <?php echo $form->errorSummary($model); ?> <?php echo ($model->isNewRecord ? $form->textFieldRow($model,'id',array('class'=>'span5','maxlength'=>32,'value'=> OpexCashAdvance::model()->getCAID(),'readonly'=>'readonly',)) : $form->textFieldRow($model,'id',array('class'=>'span5','maxlength'=>32,'readonly'=>'readonly',)) ); ?> <?php echo $form->textFieldRow($model,'amount',array('class'=>'span2','style'=>'text-align:right;font-size:16px','maxlength'=>12,'append'=>'.00','value'=>'0')); ?> <?php echo $form->labelEx($model,'department'); ?> <?php echo $form->dropDownList($model,'department', CHtml::listData(OpexDepartment::model()->findAll(),'department_id','department_name'), array('class'=>'span5','maxlength'=>12,), array('ajax'=> array( 'type'=>'POST', //request type 'url'=>CController::createUrl('OpexCashAdvance/loadcategory'), //url to call. //Style: CController::createUrl('currentController/methodToCall') 'update'=>'#OpexCashAdvance_category', //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()); ?> <?php echo $form->labelEx($model,'category'); ?> <?php echo $form->dropDownList($model,'category', /*CHtml::listData(OpexCategory::model()->findAll(array('condition'=>'department_id="'.$model->department.'"')),'category_id','category_name'),*/array(/*'empty'=>'-Select-','class'=>'span5','maxlength'=>12*/)); ?> <?php echo $form->labelEx($model,'userid'); ?> <?php echo $form->dropDownList($model,'userid',CHtml::listData(Users::model()->findAll(),'userid','userRealName'), array('empty'=>'-Select-','class'=>'span5','maxlength'=>12)); ?> <?php echo $form->labelEx($model,'branch'); ?> <?php echo $form->dropDownList($model,'branch', CHtml::listData(Branches::model()->findAll(/*array('condition'=>'department_id="'.$model->department.'"')*/),'branch_id','branch_name'),array('empty'=>'-Select-','class'=>'span5','maxlength'=>32)); ?> <?php #echo $form->textFieldRow($model,'date_created',array('class'=>'span5','maxlength'=>12,'value'=>date('Y-m-d'),'readonly'=>'readonly')); ?> <?php echo $form->labelEx($model,'date_created'); $this->widget('zii.widgets.jui.CJuiDatePicker', array('model'=>$model,'attribute'=>'date_created','value'=>$model->date_created,'htmlOptions'=>array('maxlength'=>'11','class'=>'span-5'),'options'=>array( 'showAnim'=>'fadeIn', 'showButtonPanel'=>true, 'dateFormat'=>'yy-mm-dd', ), )); ?> <?php echo $form->textFieldRow($model,'desc',array('class'=>'span6','maxlength'=>100,'style'=>'resize:none;')); ?> <?php echo $form->textFieldRow($model,'porpose',array('class'=>'span6','maxlength'=>60,'style'=>'resize:none;')); ?> <div style="width: 380px; text-align: right"> <?php $this->widget('bootstrap.widgets.TbButton', array( 'buttonType'=>'reset', 'type'=>'info', 'label'=>'Clear', )); ?> <?php $this->widget('bootstrap.widgets.TbButton', array( 'buttonType'=>'submit', 'type'=>'primary', 'label'=>$model->isNewRecord ? 'Create' : 'Save', )); ?> </div> <?php $this->endWidget(); ?>
my controller function
public function actionLoadcategory(){ $data = OpexCategory::model()->findAll( array('condition'=>"department_id='".$_POST['department']."'") ); echo "asdasdasdasdasdasd"; $data=CHtml::listData($data,'category_id','category_name'); foreach($data as $value=>$name) { echo CHtml::tag('option', array('value'=>$value),CHtml::encode($name),true); } }
i dont know why my ajax is not updating dropdownlist category any one can hep me plese, or to help me find the bug thanks in advance.
Reinhard navarro [Nhexia]