how can I trigger a function on Checkbox check action

Hi,

I am new to php as well as to yii framework. I am facing issue in triggering a function of a CFormModel derived class. How can I do that.


<div>

		<?php $modules = Yii::app()->getModules(); ?>

		<?php echo $form->labelEx($model,'selectModule'); ?>

		<?php foreach($modules as $id=>$module):?>

		<?php echo CHtml::checkBox($id, false, array('id'=>$id, 'value' => 'Y', 'uncheckValue'=>'N', 'submit'=>'', 'params'=>array('selectModule'=>$id))).ucfirst($id);?>

		<?php endforeach; ?>

		<div class="tooltip">

		Select the modules to excute the 'table.txt' i.e. a file contains table structure.

		</div>

	</div>

how can i trigger a function in above code on user selection of a checkbox.

please help.

regards

Shiv

Hi new Yii user :)

Read the definitive guide and you will understand how MVC works

chears

HI man, if new to PHP then I recommend you to extend your PHP knowledge whilst learning Yii. Yii wonders are within its guts and not knowing what that PHP does is narrowing the vision and creativity this wonderful framework provides. I have also seen a lot of weird attributes on your checkbox display, so I recommend you to navigate through the Yii API class reference too.

Now, having said that, lets provide you with a quick solution :)

Your code:

{code]

// what it is uncheckValue attribute? and submit? and params? those are weird options for HTML element tag

<?php echo CHtml::checkBox($id, false, array(‘id’=>$id, ‘value’ => ‘Y’, ‘uncheckValue’=>‘N’, ‘submit’=>’’, ‘params’=>array(‘selectModule’=>$id))).ucfirst($id);?>

[/code]

As you can see, the array sets the attributes of the HTML element, what you need to do is a hack to those attributes and include javascript function ‘onclick’ event is your answser:




<?php echo CHtml::checkBox($id, false, 

           array('id'=>$id, 'value' => 'Y', 

                     'onclick'=>'js:$(this).is(':checked')? I call the function when checked here: I call the function when not checked here;');


?>



Thats it, hope it helps you