Show/Hide fields on checkbox check/uncheck helper?

OK, this is a simple one.

I want if the user select specific drop down entry, to show a checkbox, if he checks the checkbox, show another checkbox.

Basically it doesn’t matter what selecting an entry shows, if there is such helper probably you’d specify html ID.

So - is there a helper? I can write such functionality in 1 min with plain JQuery, but I don’t know what is best practice with Yii.

Thank you all.

Then, if you can build such thing in one minute I recommend you stick with it as I do that. This is how I do it:

CHtml:: is a great class that allows you to render any form field in your document. You will find that there is a htmlOptions array as one of its parameters right? Ok, then, lets build the function (you will be surprised how easy is to do with Yii) :

CHtml::dropDownList or activeDropDownList -using dropDownList for the sake of the example:

echo CHtml::dropDownList(‘nameofthebox’,$arraydata(‘value’=>‘textofoptions’),$htmlOptions(‘onchange’=>'javascript:

//your javascript code here

'));

Thank you, Antonio.

I know CHtml quite well, I knew about HTML options but when I checked the docs for dropdown entries and checkboxes, I didn’t find the “onChange” => "javascript: " thing, as it might be generic and not dd/cb specific.

Thank you very much!

htmlOptions wraps anything as attributes - values to the tags… so for events you can use whatever correspond to:

select - checkbox - input and whatever… quite sure you know the rest :)

Cheers