dropdownlist selection update div

Hi to you all yii addicts,

It’s my first post and I need your help guys.

I have a dropdownlist in a view that shows a carousel of images. The images are taken from the database and I want to show different images type depending on the users selection(to be more specific what country the users chooses the images with the selected country_id will be shown etc)

Here is my dropdownlist in view file:

<?php echo CHtml::dropDownList(


     CHtml::listData(City::model()-&gt;findAll(),'id','title' ),array('id'=&gt;'dropDownCity') 

); ?>

and here is the query that generates the carousel:

$mainphoto_all = Images::model()->findAll(array(‘condition’ => ‘city_id=:cityid’,‘params’ => array(’:cityid’ => $selectedCity)));

My question is this:

How do I pass my value to $selectedCity and make the carousel be dynamacally updated on every new selection?

Thanks in advance

I am not sure how you are passing data to carousel, you can do either of two things.

check this dropdown calling ajax and loading data in another dropdown, you can do the same with your carousal.


        echo &#036;form-&gt;dropDownList(&#036;model,'category_id',CHtml::listData(Category::model()-&gt;findAll(&#036;crietarea),'category_id','title'),


                    'prompt'=&gt;'Select Category',

                    'ajax' =&gt; array(

                        'beforeSend'=&gt;'function(){&#036;(&quot;#Listing_subcategory_id&quot;).addClass(&quot;inputloader&quot;).attr(&quot;disabled&quot;, &quot;disabled&quot;);}',

                        'complete' =&gt; 'function(){&#036;(&quot;#Listing_subcategory_id&quot;).removeClass(&quot;inputloader&quot;).removeAttr(&quot;disabled&quot;, &quot;disabled&quot;)}',

                        'type'=&gt;'POST', //request type

                        'url'=&gt; &#036;this-&gt;createUrl('listing/Dynamiccategories'),  






The above dropdown calls the action DynamicCategories and get items

public function actionDynamicCategories()


    isset(&#036;_POST['Listing']['category_id'])? &#036;cat_id = &#036;_POST['Products']['category_id'] : &#036;cat_id = &#036;_POST['category_id'];



     &#036;data = Category::model()-&gt;findAll(array('order'=&gt;'title', 'condition'=&gt;'parent_id=:parent_id', 'params'=&gt;array(':parent_id'=&gt;(int) &#036;cat_id)));

// your images query will replace the above

    &#036;data = CHtml::listData(&#036;data,'category_id','title');

     echo CHtml::tag('option',array('value' =&gt; ''),CHtml::encode(' Select '),true);

        foreach(&#036;data as &#036;id =&gt; &#036;value)


            echo CHtml::tag('option',array('value' =&gt; &#036;id),CHtml::encode(substr(&#036;value, 0, 25)),true);



I know it not good to call POST data directly from POST array but it works for sure. Second you may pass json array using CJSON::encode($array) and update your carousel accordingly.

Or just user JQuery to call the action and update the carousel data as required