How to pass another field value to CjuiAutocomplete ?


I’m trying to use CjuiAutocomplete widgets in replacement for dependant dropdownlists. (to select a brand, a model, and a version for a classifieds application)

here is my question :

my first autocomplete works well, it allows the user to select a brand.

My second one needs to display only models from the selected brand.

I figure I need to pass the brand_id to the autocomplete action through GET.

This can be done by passing an array to the widget :

$form->widget('zii.widgets.jui.CJuiAutoComplete', array(



        'source'=>$this->createUrl('Ad/autocompleteModel', array('brand_id'=>"function() { $('#Ad_brand_id').val();}")),

        // additional javascript options for the autocomplete plugin




My problem is “function() { $(’#Ad_brand_id’).val();}” isn’t interpreted as Javascript, but just as a string…

Any idea how I can get the field value of brand_id in there?

Thanks a lot!



Use this instead

on ‘source’=>‘js:functionametocallthatwillhandlethecallwithbothvalues’

Will work

Thanks for your quick answer :)

I’m sorry, I’m not quite sure how to get a javascript function to do what I need.

The brands, models, and versions lists are stored in the database.

How can I access it through the JS function?

[edit] : I’ve figured it out :) To anyone interested :


'source'=>'js: function(request, response) {


        url: "'.$this->createUrl('Ad/autocompleteModel').'",

        dataType: "json",

        data: {

            term: request.term,

            brand: $("#Ad_brand_id").val()


        success: function (data) {






Thanks for sharing

Thank you so much !!!

Just wanted to say thanks for the solution Benn - much appreciated!