I'm having an issue with checking the value of a checkbox in CodeIgniter. I am trying to implement the solution found here: Codeigniter checking checkbox value. The following code never never evaluates to true, regardless of the checkbox being checked or not. If I add value="1" to the input, it always evaluates true.
My view:
....
<input name="Tuesday" id="Tuesday" type="checkbox" />
....
<script type="text/javascript">
.on('finished', function(e) {
var form_data = {
Tuesday: $('#Tuesday').val(),
ajax: '1'
};
$.ajax({
url: "<?php echo site_url('opportunity/create_opportunity'); ?>",
type: 'POST',
data: form_data,
dataType: 'json',
cache: false
});
})
</script>
My controller:
function create_opportunity() {
if($this->input->post('ajax')) {
$checked = $this->input->post('Tuesday');
if((int) $checked == 1) {
$Tuesday = array(
'Week_Day_Id' => 2,
'Opportunity_Id' => 18,
'Preferred' => $checked
);
}
$this->ion_auth_model->create_opportunity($Opportunity, $Tuesday);
}
}
Thanks for any help you can provide.