[Solved] Sending form via ajax onchange event


I would like to create a form which is from 2 select fields, and once the user selects an option from the first select field, it loades the correct options into the next select field.

It is like:

Yellow => Banana, Lemon

Green => Kiwi, Watermelon

Red => Apple, Strawberry

If you select Yellow in the first select field, Banana and Lemon appears in the next select field.

For this to implement I need to send the first select value to the controller through a javascript onchange event, but I can’t find how to do it properly using the tools of Yii.

I would appreciate if you could help me in the solution :)

Have a look at this wiki article (there’s more examples in the wiki and e.g. if you google using “site:yiiframework.com”).

Exactly what I was looking for. Thank you! :)

I ran into a problem again. I tried the methods explained in that article you linked, but looks like the ajax doesn’t send anything through POST to my controller. Even if I print out the whole $_POST, it return an empty array. Do you have any idea what can cause this? I use the exact same code which is in the article.

Edit: solved, I needed this row into the dropdownlist array: