How To Update Textfield's Value From Dependent Drop Down

Hi Everybody,

Hope you are all good. I have a problem that is I have a dropdown list which shows number of packages. When I select one package then it’s price should be updated in the following field of the dropdown that is a text field’s value. But unfortunately, after a long try neither I can fix the issue nor find any solution over net. Please someone help me. I pasted my form and controller’s code here.


    <div class="row">

        <?php echo $form->labelEx($model,'package_id'); ?>


        echo $form->dropDownList($model,'package_id',array(),


                'ajax' =>


                    'url'=>$this->createUrl('packagePrice'), //url to call.

                    'update'=>'#'.CHtml::activeId($model, 'price'), //selector to update




        <?php echo $form->error($model,'package_id'); ?>


	<div class="row">

		<?php echo $form->labelEx($model,'price'); ?>

		<?php echo $form->textField($model,'price',array(),array('size'=>60,'maxlength'=>128)); ?>

		<?php echo $form->error($model,'price'); ?>




    * action for service package return packages correspondent service


    public function actionPackagePrice(){

        // The following command does not work

        $data = ServicePackage::model()->findByPk(array('id'=>$_POST['package_id']));

        echo $data->price;


Kind regards,



check with firebug on the network section, if the response server answer is the correct

what can you see ?

Hi please see ex…


   echo CHtml::dropDownList('venue_name', '', CHtml::listData(Venue::model()->findAll('status!="2"'), 'id', 'venue_name'), array(

                    'id' => 'send_venue',

                    'prompt' => 'Select Venue',

                    'class' => 'col_165',

                    'ajax' => array(

                        'type' => 'POST',

                        'url' => CController::createUrl('eventname'),

                        'update' => '#event_name',

                        'data' => array('venue_id' => 'js:this.value'),



<div id="#event_name"></div>  


public function actionEventname(){


        $data=VenueEvent::model()->findAll("rk_venue_id='".$venue_id."' AND status='1'");



        foreach($data as $value=>$event_name){

            echo CHtml::tag('option', array('value'=>$value),CHtml::encode($event_name),true);




Hi KonApaz,

Thanks to reply. I have checked through firebug and found the response is correct that I got the price value. Just I can’t place that value(price) in the value of textfield correctly.

Firebug result of HTML

<input type="text" maxlength="128" id="Sell_price" name="Sell[price]">150</input>

the value 150 of the above code should be placed in value="150"

Many thanks

Hi Modi,

Thanks to reply. I tried this way but I am little confused how to update.


Hi ,

first you can create the the div before the textfield

<div class="update">

<?php echo $form->textField($model,'price',array(),array('size'=>60,'maxlength'=>128)); ?>


and change the ajax update value


i hope it’s work

Yes it makes sense. thank you.

check this