checkbox return unchecked

hello everyone, i have a little problem with the checkbox, by default the checkbox send 1 if was checked and send 0 if was unchecked, but i send ‘S’ if was checked and ‘N’ if was unchecked and i want to return checked if i send S but returns me unchecked, how i fix that, my checkbox works but when i send ‘S’ checkbox marked as unchecked, this is my code




<div class="row">

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

   <?php echo $form->checkBox($model, 'REFERENCIA4', array('size'=>1,'maxlength'=>1, 'value'=>'S', 'uncheckValue'=>'N')); ?>

   <?php echo $form->error($model,'REFERENCIA4'); ?>

</div>



y try to use jQuery but doesn’t work too




    var ref = '".$model->REFERENCIA4."';		    

    if (ref == 'S')

    $('#tra_pedido2h_REFERENCIA4').attr('checked', true);

    else

    $('#tra_pedido2h_REFERENCIA4').attr('checked', false);



instead of using value as a html option give that value to the attribute like


$model->REFERENCIA4='S';

give that value to attribute in where? jQuery? sorry but im newbie lol

Think a bit… where is the $model variable used in your code… certainly not in jQuery…

that’s PHP… you can set it in the controller just before rendering the view.

yeah, i understand your point, actually i tried before and the checkbox return me no marked and if i do that i set only S in the checkbox and if i want to send N?

Define your checkbox in view as your did:


<div class="row">

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

   <?php echo $form->checkBox($model, 'REFERENCIA4', array('size'=>1,'maxlength'=>1, 'value'=>'S', 'uncheckValue'=>'N')); ?>

   <?php echo $form->error($model,'REFERENCIA4'); ?>

</div>

in controller action, if you set $model->REFERENCIA4=‘S’ checkbox gets checked, if you set $model->REFERENCIA4=‘N’ checkbox will be unchecked. Simple as that.

thanks all, i solved, well, i don’t know if i explain very well, but my checkbox always work, my problem was that the checkbox coming not marked when i checked with S and the problem was a blank spaces that coming in the Data Base so i use trim and that’s it, thanks anyway