CFormBuilder and how to insert javaScript

Hi there,

I’m currently investigating yii CFormBuilder and would like to create a form that shows/hides an element when a checkbox element is clicked.

I would like to define the javascript (or the location) for this javaScript in the Form template array that defines the form.

Is this possible?

Is this the wrong way to go about thinking about this?

Where would you put the form specific javascript?

Thanks.

Well you can do this task as you are expecting…you just have to create a form element which you are expecting on with a CFormbuilder like checkbox. and call a javascript function on the checkbox.

Define a javascript as you want like on the same view file or register it in a view file.

Now to create a Dynamic Form field with javascript.You can create html field on the form.

To check the format of form element check the HTML source of form and create a html element which you want to create on form. ;)

let it try and share your experience…

Thanks for the infos. It occurred to me also.

This is what I did, in my elements array in the form builder definition array;


'elements' => array(

		'Question1'=>array(

			'type'=>'radiolist',

			'items'=>array('yes'=>'Yes', 'no'=>'No'),

			'hint'=>'the hint',

			'attributes' => array('onClick' => 'javascript:alert(\'****\');'),

		),