[solved] Change JavaScript event-handler for Ajax-Request

Hi folks,

first of all I have to say, that Yii is a great framework that turns coding into fun but I have one small problem.

This is my code in my view template that sends an ajax request to the given controller action when the text field value changes (onchange):



<?php


echo CHtml::textField(


                'myTextField',


                'testValue',


                array(


                    'ajax' => array(


                        'type'=>'GET',


                        'url'=>'nofilter?function=genres&albumId=1',


                        'update'=>'#myAjaxDiv1',


                    ),


                )


);


?>


What do I have to do, if I want to send the ajax request when I focus the text field. I know I have to change the event-handler to "onfocus" but I don't know how to use the method "clientChange()".

Can anybody help me?

Thanks in advance,

Sven

You can use the following code:



<?php


echo CHtml::textField(


    'myTextField',


    'testValue',


    array(


    	'onfocus'=>CHtml::ajax(


			'type'=>'GET',


			'url'=>'nofilter?function=genres&albumId=1',


			'update'=>'#myAjaxDiv1',    	


    	),


    ),


);


        


Hi qiang.

Thanks, it works great. But I had to change a litte thing:



echo CHtml::textField(


                'myTextField',


                'testValue',


                array(


                    'onfocus'=>CHtml::ajax(


                        array(


                           'type'=>'GET',


                           'url'=>'nofilter?function=genres&albumId=1',


                           'update'=>'#myAjaxDiv1',


                        )


                    ),


                )


);


CHtml::ajax requires an array to work.

Best regards,

Sven