CAutocomplete second parameter


I’m using CAutocomlete very successfully but have a problem with a second parameter




	'name'	=> 's',

	'value' => $sValue,

	'url'	=>	array('translation/autoCompleteLookup'), 


 	'extraParams'	=> array('l' => $dCl),


	'minChars'	=>	2, 

	'delay'		=>	10,

	'matchCase'	=>	false,


	'htmlOptions'=>array('size'=>'40', 'id' => 'searchfield' ), 

	'methodChain'=> ".result(function(event,item){\$(this).parents(form).submit();})",



I have a dropdown next to my input field, but i don’t know how to get the selected value to autocomplete?!

<select name="l">

&lt;option value=&quot;1&quot;&gt;BMW&lt;/option&gt;

&lt;option value=&quot;2&quot;&gt;AUDI&lt;/option&gt;

&lt;option value=&quot;3&quot;&gt;SEAT&lt;/option&gt;


If the user selected an AUDI, than extraParams should get 2 as a value.

Please help me!

thank you!


try the following in your view




//insert the ID of your select

'methodChain'=>".result(function(event,item){\$(\"#1\").val(item[1]); })",


in the controller

public function actionAutoCompleteLookup()


if(Yii::app()->request->isAjaxRequest && isset($_GET['q']))



$criteria = new CDbCriteria;

$criteria->condition = ...;

$criteria->params = ...;

$resultArray = MyModel::model()->findAll($criteria);

$returnVal = '';

foreach($resultArray as $resultItem)


//this is the code to return name and id

$returnVal .= $resultItem->getAttribute('name').'|'



echo $returnVal;



hope this can help you, it works fine for me



thank you for your reply, but it doesn’t work.

'methodChain'=>".result(function(event,item){\$(\"#l\").val(item[1]); })",   // NEW

'methodChain'=> ".result(function(event,item){\$(this).parents(form).submit();})",   // OLD

l for categorie should be give as an extra Parameter

oh, sorry, i misunderstood what you wanted to do…the code i posted is not suitable for your situation…i thought you were trying to set the value from autocomplete to the select option input

accordling to the docs, I’d try to get the l value in the controller as

$l = CHttpRequest::getParam('l', null);


my english is very terrible :(

is it possible to load the selected value from the dropdown list to

'extraParams'   => // HERE JQUeRY?<img src='' class='bbc_emoticon' alt='???' />?

please, see this topic answered by Qiang:

i haven’t tested it, but it seems that extraParams also accepts a “js:function(){ }”

thanks for reply.

But what does he mean?


think that you can do something like

"js:function(){ //code to return $('#div_to_get_value_dinamic').val(); }"