Ajax dropdownlist not working

Hi,

I’m testing ajax features and I’m having a problem getting a dependant dropdownlist to work.

I have the following index.php:




<div id="data">

   <?php $this->renderPartial('_ajaxContent', array('myValue'=>$myValue)); ?>

</div>


<?php echo CHtml::beginForm(); ?>

   <div class="row">

		Proyecto:

		<?php 

      echo CHtml::dropDownList('combo_proyectos','',Modelo::proyectos(),

        array('ajax'=>array('type'=>'POST','url'=>CController::createUrl('site/seleccionProyecto'),array('update' =>'#data')))); 

      echo CHtml::ajaxButton ("Seleccionar",CController::createUrl('site/seleccionProyecto'),array('update' =>'#data')); 

    ?>

	</div>

<?php echo CHtml::endForm(); ?>

</div>

<?php

}

?>



The SiteController class has the following methods:




	public function actionIndex()

	{

		// renders the view file 'protected/views/site/index.php'

		// using the default layout 'protected/views/layouts/main.php'

    $data = array();

    $data["myValue"] = "Content loaded";

 

    $this->render('index', $data);

	}


  public function actionSeleccionProyecto()

  {

    $data = array();

    $data["myValue"] = "Content updated in AJAX";

    $this->renderPartial('_ajaxContent', $data, false, true);

  }




_ajaxContect just displays the data.

The problem is that when the button is clicked the action is called and the message is changed dinamically, but when an item of the drop down is selected nothing happens.

Thanks




echo CHtml::dropDownList('combo_proyectos','',Modelo::proyectos(),

        array('ajax'=>array('type'=>'POST','url'=>CController::createUrl('site/seleccionProyecto'),'update' =>'#data'))); 




Try this.

Ajax options only takes one parameter: public static function ajax($options)

Please ignore this post. I found that the ‘update’ argument was inside an array. Problem solved.

Can you post the correct code for any future readers of this post.

Thanks

Yes please, post the correct code as I’d like to know too. Thanks.

Please I would to see the code too, I have the same problem


<div id="data">    <?php $this->renderPartial('_ajaxContent', array('myValue'=>$myValue)); ?> </div>  <?php echo CHtml::beginForm(); ?>    <div class="row">                 Proyecto:                 <?php        echo CHtml::dropDownList('combo_proyectos','',Modelo::proyectos(),         array('ajax'=>array('type'=>'POST','url'=>CController::createUrl('site/seleccionProyecto'),array('update' =>'#data'))));        echo CHtml::ajaxButton ("Seleccionar",CController::createUrl('site/seleccionProyecto'),array('update' =>'#data'));      ?>         </div> <?php echo CHtml::endForm(); ?> </div> <?php } ?>

u have to change the code to…


<div id="data">    <?php $this->renderPartial('_ajaxContent', array('myValue'=>$myValue)); ?> </div>  <?php echo CHtml::beginForm(); ?>    <div class="row">                 Proyecto:                 <?php        echo CHtml::dropDownList('combo_proyectos','',Modelo::proyectos(),         array('ajax'=>array('type'=>'POST','url'=>CController::createUrl('site/seleccionProyecto','update' =>'#data'))));        echo CHtml::ajaxButton ("Seleccionar",CController::createUrl('site/seleccionProyecto','update' =>'#data'));      ?>         </div> <?php echo CHtml::endForm(); ?> </div> <?php } ?>

change the code

array(‘update’ =>’#data’)

to

‘update’ =>’#data

is there any way in which i can trigger ajax on onlaod event in a dropdown…in other words can i change the defalult evnt that is I hope onclick to some another event like onlaod …etc