最新消息: 新版网站上线了!!!

Yii dropDownList onChange

 

        labelEx($model,'clientid'); ?>
        textField($model,'projectid'); ?>
         dropDownList($model,'clientid', CHtml::listData(Client::model()->findAll(), 'code','name'),
                                array(
                        'prompt' => '--Please Select --',
                        'value' => '0',
                        'ajax'  => array(
                        'type'  => 'POST',
                        'url' => CController::createUrl('task/projects'),
                        'update' => '#Task_projectid',   //selector to update value 
                        'data' => array('clientid'=>'js:this.value'),
                        )       
                        )
        ); ?>

 



   

                labelEx($model,'projectid'); ?>
                dropDownList($model,'projectid', array('empty'=>'--please select--')); ?>
                error($model,'projectid'); ?>
       

The controller action

 public function actionProjects()
        {
        $giatUnit = (!empty($_POST['clientid'])) ? $_POST['clientid']: '0';

                $data=Project::model()->findAll('clientid=:clientid',
                                array(':clientid'=>$giatUnit));


                $data=CHtml::listData($data,'id','name');
                foreach($data as $value=>$name)
                {
                echo CHtml::tag('option',array('value'=>$value),CHtml::encode($name),true);
                }       


        }
 

转载请注明:谷谷点程序 » Yii dropDownList onChange