i am newbie in codeigniter and jquery but the website i am maintaining now uses this framework and language,.,.the problem is that i have these text fields and hidden fields in a page,,.i want to get the values of these input fields through jquery,.,passed these through $.post of jquery to a Controller,.,.i know how to track the flow but i do not know how to get the passed value in my controller and i am totally newbie in codeigniter and jquery,,i want to learn and at the same time finished the task,.,. heres my code in my view page..
<?php $date = date('m/d/Y');
$ts = strtotime($date);
$year = date('o', $ts);
$week = date('W', $ts);
for($i = 1; $i <= 7; $i++) {
$ts = strtotime($year.'W'.$week.$i);
?><input type="text" name="days" class="days" /><input type="hidden" id="date_now" name="date_now" value="<?php print date("Y-m-d", $ts); ?>" />
}
?>
and my jquery for text input
$(".saveTimeSheet").click(function() {
var days_array = [];
var date_now_array = [];
$('.days').each(function() {
days_array.push($(this).val());
});
$.post("<?php print base_url().'index.php/MyController/saveTimeTable'?>", {days_array: days_array},
function(data){
if(data=='success')
{
alert('success');
}
else{
error_message(data);
}
});
});
MyController Code...
function saveTimeTable()
{
$idnum=$this->session->userdata('id');
$duration=$this->input->post('days_array')*3600;
$this->mmyhr->modeSaveTimeTable($idnum, $duration);
}
my Model code(mmyhr)
function modeSaveTimeTable($idnum, $duration)
{
$this->db->set('employee_id', $idnum);
$this->db->set('duration', $duration);
$this->db->insert('hs_hr_time_event');
}
could anyone help me,.,.please....
$idnum&$duration) are getting the correct values?) ??days_arraywill be received as array. How can you multiply it directly without using loop?$this->input->post('days_array')*3600