changing activeTextField value depending on values which were chosen in activeDropDownList via Ajax.

Hi guys,

I am having a problem with AJAX query.

I need to implement the following functionality:

User is choosing a value in activeDropDownList I am passing this value to controller via ajax request and according to this value, controller should change

value of activeTextField(for example make it disabled and assign text to value field.)

I was making my research based on the following article from Yii Cook Book, it’s a little bit different from

what I am trying to achieve but I’ve took a concept from there.

So this is my activeDropDownList

<?php echo CHtml::activeDropDownList($model,'fromtype',CHtml::listData( policygrouptype::model()->findAll(), 'id', 'description' ),


								'ajax' => array(

								'type'=>'POST', //request type

								'url'=>'index.php?r=policy/dynamicinput', //url to call

								'update'=>'#policy_fromvalue', //selector to update

								//'data'=>'js:javascript statement' 

								//leave out the data key to pass all form values through



And here is my activeTextField which should be changed dynamicly.

<?php echo CHtml::activeTextField($model,'fromvalue',array('size'=>60,'maxlength'=>250,'id'=>'policy_fromvalue')); ?>

So can anyone help me in writing functionality for the controller to achieve my goal, so far I have an impression that my ajax query is not working, since

no new Jquery event handler can be detected on a page, I am using Firebug for monitoring this.

I had also an impression that something should be turned on in Yii config file to enable AJAX requests.

Thanks for your help.

Guys, really need this to be done, please help!

UP, Anyone?

For a start, you need to verify that the Ajax request reaches your controller action. You should be able to see the request in the Firebug console. Or you can add trace messages to your ‘dynamicinput’ action. You need to have file logging enabled, the trace messages will be written to protected/runtime/application.log.

What is different from http://www.yiiframew…oc/cookbook/24? Maybe you should do a forum search for activeDropDownList and Ajax. If still no luck, try to explain more in detail which part of the request/update cycle doesn’t work.


It might also be worth the time to manually create the javascript code. The current CHtml integration is very limited, but the generated js is good enough to begin with.

Hi, I am aware how controllers are working and I know that I need to write my functionality in action with name dynamicinput.

As I’ve mentioned in my previous message, I am using firebug and can’t see request at all(when I choose value in drop down list, as far as I understand some Jquery event handler should be generated. But it isn’t.

Thanks for help anyway. Will continue to dig :)

Is jquery.js included in the head section of your page?

Do you see a script block similar to this at the end of your page?

<script type="text/javascript">


jQuery(document).ready(function() {


jQuery('#objid').change(function(){jQuery.ajax( ...






Use attribute ‘success’ instead of ‘update’. See example code:

<div class="simple">

<?php echo CHtml::activeLabelEx($model,'pi_codigo'); ?>

<?php echo CHtml::activeDropDownList($model, 'pi_codigo', 

           CHtml::listData(cvp_pi::model()->findAll(array('order'=>'pi_numero')), 'pi_codigo', 'pi_numero'),

           array('empty'=>'(Todos os PIs)',            

                 'ajax' => array(

                                  'type'         => 'GET',

                                 'url'         => array("/{$this->module->id}/pi/carregarValorPi"),

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

                                 'success'    => 'js:function(valor){ $("#rel_valor").val(valor) }'


                )); ?>


<div class="simple">

<?php echo CHtml::activeLabelEx($model,'rel_valor'); ?>

<?php echo CHtml::activeTextField($model,'rel_valor',

                array('id' => 'rel_valor', 'size'=>10,'maxlength'=>10, 'disabled'=>true)); ?>