Add jQuery to controls that were added to a form via ajax

So I have a dynamic form I’m using to build an SQL query. Each row of the form has another condition (i.e. 1 row would be “AND customerName LIKE Joe”), and rows can be added dynamically when the “Add Row” button is pressed (ajax). When one drop down list is changed, I use an ajax query to grab the contents of a subsequent drop down list (certain operators make sense only for certain parameters). The existing dynamic dropdownlists work, but not new ones that are added the form dynamically. I’m thinking I may have to use something like ‘ajaxComplete’ or ‘ajaxSuccess’, but I’m not sure how. I believe this is because if I spit out CHtml::activeDropDownList(…) from within an ajax response, Document.onLoad doesn’t get called again, so the .change function never attaches to the drop down list. How can I attach the .change function to a dropdownlist that is generated inside an ajax response?

Thanks in advance!

Tom

Try to do, in your controller, instead of




$this->renderPartial('view', $data);






$this->renderPartial('view', $data, false, true);



The fourth parameter setted to true mean

You have always to do like that if you create in ajax reponses stuff that need javascipt code.