I’m trying to post to the controller some data that I retrieve from the form. Here is my form:
<div id="time_registration" class="toogle_form" diplay="none">
<form id="hourForm" name="hourForm" >
//first part of the form -----
//second part:
<div id="hoursDetails" class="toogle_form" style="display:none">
<table border=0>
<?php
for ($i=0 ; $i<3; $i++){
echo '<tr>
<td><div id="date'.$i.'" name="date'.$i.'" ></div></td>
<input type=hidden id="date'.$i.'" name="date'.$i.'" value=""/>
<td>
<input type=text name="action'.$i.'" placeholder="Votre action" value=""/>
<input type="text" name="temps'.$i.'" placeholder="nombre heures" value=""/>
</td>
</tr> ';}
echo ' <input type=hidden id="dateTest" name="dateTest" value=""/> '; // just to test
?>
</table>
</div>
</form>
</div>
Firebug shows that date0, date1 and date2 are empty but dateTest is not.
Here is how I set my variables ( js function)
for (var i = 0; i < 3; i++) {
$('#date'+i).html('myVariable');
$('#date'+i).val('myVariable');
}
$('#dateTest').val('dateTest');
And here is how I post the data to the controller :
function insert_hour() {
var form_values= $('#hourForm').serialize();
alert($('#date0').val());// prints the correct value also for date1 and date2
$.ajax({
type:'POST',
url : '<?php echo site_url()."/path/to/controller/"; ?>',
data : form_values,
success:function(data)
{ alert(' ajax_call ok ');
}
});
}
I think you are doing here wrong
In this case
$('#date'+i).html('myVariable'); Will not work
You are using same id.Id must be unique.