Question

I have a Chtml::link like this:

echo CHtml::link('DESACTIVAR',array ('/ZfIncidencias/estado', 'id'=>$data->incidencia_id),array("class"=>"desactivar"));

This execute the action, but what I need is this:

$id_on = $data->incidencia_id;
                $content_on = '<div class="onoffswitch">
                    <input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="'.$id_on.'" checked />
                    <label class="onoffswitch-label" for="'.$id_on.'">
                        <div class="onoffswitch-inner"></div>
                        <div class="onoffswitch-switch"></div>
                    </label>
                </div> ';
                echo CHtml::link($content_on,array('/ZfIncidencias/estado', 'id'=>$data->incidencia_id));

And when I click the action is not executed.

There is a way to force it to execute?

SOLUTION:

$id_off = $data->incidencia_id;?>
                <div class="onoffswitch">
                    <input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="<?php echo $id_off;?>" unchecked onClick="javascript:location.href = '<?php echo Yii::app()->baseUrl.'/ZfIncidencias/estado/'.$data->incidencia_id;?>'"; />
                    <label class="onoffswitch-label" for="<?php echo $id_off;?>">
                    <div class="onoffswitch-inner"></div>
                    <div class="onoffswitch-switch"></div>
                    </label>
                </div>
Was it helpful?

Solution

You need to use Ajax call here. If you don't want to reload the page again then you can use Jquery.post();

Check the JSFiddle and modify the class as per your needs in the function.

$(document).on("click",".onoffswitch-checkbox", function(){
    var id = $(this).attr('id');
    $.post('/ZfIncidencias/estado/'+id, "", function(data){
        //Change the class here
    });
});

http://jsfiddle.net/z9xQM/1/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top