Yii dynamic dropdown output to view

Using this wiki I have a dynamic dropdownlist working just fine. Instead of the related data populating another dropdownlist I just want all the related values to display at once on the screen in some sort of formatted list.

I changed the update in the ajax action to ‘update’=>’#cities’, and added to my view…


<div id="cities"> 

   <?php echo $model->relatedCities; ?>

</div 

and to my model


public function getRelatedCities()

{

   $out=CHtml::listData($this->cities,'CityId','Name');

   return implode('<br />', $out);

}

When I make my selection in my dropdownlist nothing is updated in <div id="cities"> and the ajax call in firebug looks fine.

So how can I display the dynamic related content from the dropdownlist all at once?

This is a problem with your action, you have to echo instead of return.

Because your ajax call is expecting html data, and not some string.

So try this:




public function getRelatedCities()

{

 $out=CHtml::listData($this->cities,'CityId','Name');

 echo implode('<br />', $out);

}



p.s: Assuming that you have verified that $out is not empty.

I have already given this reply to your S.O question.

Do give some feedback.

By the way, what I like to do when dealing with Ajax is to use a Firefox addon called Live HTTP Headers. You can see the HTTP requests for all triggered ajax events, and can easily ‘replay’ requests, ensuring that the http requests are returning your desired output.

Perhaps Firebug can do that, but I’ve never really used it for that reason :P