I am using ajax to update a table. The table has multiple date inputs and I would like to have a datetimepicker popup when any of the inputs are clicked.
I have tried assigning a class to the input but nothing happens and I get no errors in console. I am just learning jquery, javascript so, I apologize if this is a stupid questions.
I am using the below code to initialize the datetimepicker:
<!-- Datepicker -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.7.14/js/bootstrap-datetimepicker.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.7.14/css/bootstrap-datetimepicker.min.css">
$( document ).ready(function() {
$('.dateedit').each(function(){
$(this).datetimepicker();
});
});
I am using the following code to populate my table:
$.ajax({
url:"<?php echo base_url(); ?>clock/search_data",
method:"post",
dataType:"JSON",
data:{fromDate:fromDate, toDate:toDate, userId:userId},
success:function(data){
console.log(data)
var html = '<tr>';
for(var count = 0; count < data.length; count++){
html += '<tr>';
html += '<td class="table_data" data-row_id="'+data[count].id+'" data-column_name="id" >'+data[count].first_name+" "+data[count].last_name+'</td>';
html += '<td><input type="text" class="dateedit" data-row_id="'+data[count].id+'" data-column_name="clock_in" value="'+data[count].clock_in+'"></td>';
html += '<td><input type="text" class="dateedit" data-row_id="'+data[count].id+'" data-column_name="clock_out" value="'+data[count].clock_out+'"></td>';
html += '<td class="table_data" data-row_id="'+data[count].id+'" data-column_name="time">'+data[count].time+'</td>';
html += '<td><button type="button" name="delete_btn" id="'+data[count].id+'" class="btn btn-xs btn-danger btn_delete"><span class="glyphicon glyphicon-trash"></span></button></td></tr>';
}
$('tbody').html(html);
}
});
}
I am using the below code to perform my database update function:
$(document).on('change','.dateedit', function () {
var id = $(this).data('row_id');
var table_column = $(this).data('column_name');
var value = $(this).val();
$.ajax({
url:"<?php echo base_url(); ?>clock/update",
method:"POST",
data:{id:id, table_column:table_column, value:value},
success:function(data){
console.log(data)
search_data();
}
})
});
No matter what I seem to change I cannot get the datetimepicker to populate. Any help is appreciated.