当我按下保存按钮时,复选框没有保持检查状态

时间:2013-11-06 12:55:41

标签: php codeigniter

<?php 
$options = array(
 'infant'  => '1',
 'mater'    => '2',
 'prees'   => '3',
 'kinder' => '4', );

echo form_open('evals/proc_group'); 
echo form_checkbox('edu_level[]','1', in_array('1', $educational_levels)); echo form_label ('Infantes', 'infant',  array ('class' => 'checkbox_label'));
echo form_checkbox('edu_level[]','2', in_array('2', $educational_levels)); echo form_label ('Maternales', 'mater',  array ('class' => 'checkbox_label'));
echo form_checkbox('edu_level[]','3', in_array('3', $educational_levels)); echo form_label ('Preescolares', 'prees',  array ('class' => 'checkbox_label'));
echo form_checkbox('edu_level[]','4', in_array('4', $educational_levels)); echo form_label ('Kindergarten', 'kinder',  array ('class' => 'checkbox_label')); ?>

<input type="hidden" name="eval_id" value="<?php echo $evaluation->id ?>" />                                   
<div class="clear"></div>                                       
<?php echo form_submit('mysubmit','Guardar Grupo'); ?> 
<div class="clear"></div>
<?php echo form_close(); ?>
<div class="clear"></div>

当我按下Guardar Grupo时,我需要选中复选框。我该怎么办?

2 个答案:

答案 0 :(得分:0)

希望这会有效,我自己没有检查过代码。

var checkboxes = $('.checkbox_label');
for ( i = 0 ; i < checkboxes.length; i++ ) {
    checkboxes[i].prop('checked', true)
}

您必须将此添加到表单的提交按钮单击事件。

答案 1 :(得分:0)

执行print_r($educational_levels)以查看数组是否包含值。除此之外,我看不到任何异常。还要确保此$educational_levels是一个单维数组 这对我很有用:

public function index()
{
    //$this->load->view('welcome_message');
    $this->load->helper('form');
    $educational_levels = array('1', '3');
    echo form_checkbox('edu_level[]','1', in_array('1', $educational_levels));
}

您需要检查数组$educational_levels contains values是否为not empty!