I am creating a website with 3 sections: get item, workplace, and change logs.
The way I want the website work is that: you first get an item, then the item is loaded into Workplace (as a table, with dropdowns, calendar for you to change the info) using Ajax, then you make changes/hit submit and changes will appear on the Change logs using again Ajax.
This way my whole webpage doesn't have to refresh every time get Item or submit changes.
ALSO, when you get the item, i put it in a SESSION, and the WorkPlace is generated by pulling data from database based on this session's info using Ajax.
If user hit refresh, i also have static code to load the Workplace table from the database using info from the SESSION
I got almost everything done. However, there is a datepicker in the Workplace that only works if you hit refresh the page. AKA only work if the static code runs. If the Workplace table is generated through Ajax, the datepicker doesnt work.
Here is my code:
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/css/bootstrap-datepicker.standalone.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/js/bootstrap-datepicker.min.js"></script>
$x = 0;
foreach ($_SESSION['working'] as $ItemInWorking) {
echo '<div class= "changeDate" class="input-group date mt-1">';
echo '<input type="text" class="form-control" class="datepicker" id="datepicker{$x}" placeholder="{$ItemInViewing['EFFECTIVE_DATE']}" value="{$ItemInViewing['EFFECTIVE_DATE']}">';
echo '</div>';
$x++
}
<!-- Script for Datepicker -->
<script type="text/javascript">
$("body").on("click", ".changeDate", function(){
// $(document).ready(function() {
$('[id^=datepicker]').datepicker({
format: "dd-M-yy",
startDate: "yesterday",
todayBtn: true,
autoclose: true,
todayHighlight: true
});
return false;
});
</script>
Did I do something wrong? Please help. Any help is appreciated!
EDIT:
console does not give me any error. it just that when I get Item, the table is created, but when i click to change date, the Calendar does not show up.
I would have to refresh the page, aka, let the static code run, then I can click and see the calendar. But i also have to click twice?..