Ajax Checkbox With Two Different Url

I have a checkBox and I use ajax in it. What I want to do is to use one ‘url’ parameter when I check and another different one when I uncheckit. For example:

When I check:

'url'=> CController::createUrl('/item/add'),

When I uncheck:

'url'=> CController::createUrl('/item/remove'),

Of course I do not want to check the state of the checkBox in the view from the controller.

What is the best approach for it?

Thank you

No answers? no suggestions? I will try with a button group, two buttons that toogle. Different buttons, different ‘url’ parameters. It should work.

Thank you anyway


When I check and uncheck:

'url'=> CController::createUrl('/item/operation'),param=>array('operation'=>$this.selected?'add':deletion),

This can work…but not tested

It does not work for me. $this refers to the controller, and $this.selected does not exist.

I would do it this way:

<input type="checkbox" id="chk" />


$url1 = $this->createUrl(...);

$url2 = $this->createUrl(...);

$js = <<<JS


    $.post(this.checked ? "$url1" : "$url2", ...);



Yii::app()->clientScript->registerScript('chk', $js);


Thank you!!! It works!!! My final code is:

<input type="checkbox" id="chk">


	$url1 = $this->createUrl('/item/add');

	$url2 = $this->createUrl('/item/remove');

	$js = '


	    $.post(this.checked ? "'.$url1.'" : "'.$url2.'", function(data) {





	Yii::app()->clientScript->registerScript('chk', $js);