Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- echo $form->dropDownList($model, 'service_id', CHtml::listData(Service::model()->findAll(array('order'=>'description,code')),'id','description'),
- array(
- 'prompt' => 'Select Service ...',
- 'ajax' => array(
- 'type'=>'POST', //request type
- 'url'=>CController::createUrl('updatePrice'), //url to call.
- 'data'=>array('service_id'=>'js:this.value'),
- 'dataType'=>'json',
- 'success'=>'js:function(data) {
- var price="#'.CHtml::activeId($model, 'price').'";
- $("#price_id").value(data.price);
- }',
- )
- )
- );
- ?>
- <?php // in the ServiceContoller.php of above
- public function actionUpdatePrice() {
- if (Yii::app()->request->isAjaxRequest) {
- $service=Service::model()->findByPk($_POST['service_id']);
- if (isset($service))
- echo CJSON::encode(array(
- 'price'=>$service->defaultPrice,
- ));
- else
- echo CJSON::encode(array(
- 'price'=>0.00,
- ));
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement