How To Call Javascript In Yii Dropdownlist Onselect

I created two dropdownlists using Chtml::dropdownlists as shown below.




    echo $form->dropDownList($model, 'min_cost', Yii::app()->params['cost_resales'], 

                                      array(

                                              'empty'=>'Choose one', 

                                              

                                              )

                                      );

     echo $form->dropDownList($model, 'max_cost', Yii::app()->params['cost_resales'], 

                                      array(

                                              'empty'=>'Choose one', 

                                              

                                              )

                                      );



Now, the above code has to work according to the below script







    // Keep a copy of the default options

    var $options = $('#SearchForm_min_cost').children().clone();

    

    

    $('#SearchForm_min_cost').change(function(){

    // Within your change handler:

    

    var index = $(this).find(':selected').index();

    $('#SearchForm_max_cost').html($options).children(':lt('+index+')').remove();

    

    });    



I created a fiddle <http://jsfiddle.net/E3mY2/1/> with the above code. In fiddle it works fine. But, I don’t know how to call the script in order to make the dropdownlists work

make sure you have jquery loaded


$(function(){ 

   // Keep a copy of the default options

    var $options = $('#SearchForm_min_cost').children().clone();

    

    

    $('#SearchForm_min_cost').change(function(){


    // Within your change handler:

    

        var index = $(this).find(':selected').index();

        $('#SearchForm_max_cost').html($options).children(':lt('+index+')').remove();

    

    }); 


});

if it does not work at least bother to explain what exactly you trying to achieve

Thanks for the reply …It works now

glad could help