SilverRay SilverRay - 7 months ago 11
SQL Question

Codeigniter access input type inside echoed table

I have a table echoed inside from controller and loaded into a div id via jquery trigger event. The problem is that the table consists of input type texts that I made to datepickers but it's not working. Here is my code inside the controller:

echo "<table class='table table-striped table-borderless' width='100%'>
<tbody>
<tr>
<td><label class='control-label'>AWOL</label></td>
<td><select class='form-control' id='cmbawol1' name='cmbawol1'>";
$awol_code = array();
$awol_code[] = $val['AWOL'];
echo "<option value='".$val['AWOL']."'>".$val['AWOL']."</option>";
foreach($data['offense'] as $value)
{
if(!in_array($value['Offense'],$awol_code))
{
echo "<option value='".$value['Offense']."'>".$value['Offense']."</option>";
}
}
echo "</select></td>
<td><input type='text' class='form-control' id='txtawol1' name='txtawol1' value='".$date1."'/></td>
</tr>


and this is the jQuery that I always use to create datepicker:

$('#txtawol1').datepicker();


For other pages it works because they are not echoed inside the controller. Please note that this table is inside my edit function meaning it have a default value from my database.

I have the table structure with button on on the last column and I access it via this code:

$(document).on('click','#btnviolation',function(){
............code goes here
});


But I don't know how for input types.

Answer

OK I solved y own problem and this is my solution:

$(document).on('focus','#txtawol1',function(){
$(this).datepicker();
});

I hope that others may find my code helpful too.