Html code:
<input type="checkbox" id="my_data" name="my_data" value="1" <?php echo($my_data == 1 ? 'checked' : ''); ?>/>
Controller code:
$my_data_val = isset($_POST['my_data']) && $_POST['my_data'] ? "1" : "0";
$data["my_data"] = $my_data_val;
i want checked the check box by default while page loading.
Error result : check box value 0 or unchecked while page loading.
In the controller, pass the data as
$data["my_data"] = $my_data_val;
$this->load->view('myfile' , $data);
While in the view:
<input type="checkbox" id="my_data" name="my_data"
value="1" <?php if($my_data==1) echo "checked='checked' "; ?>
/>
Add follow code to your controller to pass the data
$data["my_data"] = $my_data_val;
$this->load->view('myfile' , $data);
Your view looks OK
do like this
echo form_checkbox('name', 'value', TRUE);//true for checked
put like this if(your condition){//here}