I am using Bootstrap 3 Datepicker. And when I select the start date, then in end date automatically gets filled in another field to the next date. I just cannot figure out why I am getting it. The code is working fine in Firefox and Chrome but in Safari console, it's giving me an error. Any idea why I might get.
SyntaxError: Expected an identifier but found '[' instead
The Code:
<div class="row">
<div class="col-xs-5 search_date">
<label>{{lang('start_date')}}</label>
<input type='text' name="start_date" id="start_date" value="<?php echo @$start_date; ?>" required=""/>
<span class="text-danger"><?php echo @$error['start_date']; ?></span>
<input style="border:0;" type="text" name="start_time" id="start_time" required="" class="" value="<?php echo @$start_time; ?>" />
<span class="text-danger"><?php echo @$error['start_time']; ?></span>
</div>
<div class="col-xs-2 p-t40">
<img src="{{ asset('images/web/arrow-right.png') }}" class="m-t40">
</div>
<div class="col-xs-5 search_date">
<label>{{lang('end_date')}}</label>
<input type="text" name="end_date" id="end_date" required="" class="" value="<?php echo @$end_date; ?>" />
<span class="text-danger"><?php echo @$error['end_date']; ?></span>
<input style="border:0;" type="text" name="end_time" id="end_time" required="" value="<?php echo @$end_time; ?>" />
<span class="text-danger"><?php echo @$error['end_time']; ?></span>
</div>
</div>
<script>
$(function () {
$('#start_date').datetimepicker({
format: 'DD-MM-YYYY',
minDate: moment().add(1, 'days'),
});
<?php if (isset($start_date)) { ?>
$('#start_date').val('<?php echo @$start_date; ?>');
<?php } ?>
$('#end_date').datetimepicker({
format: 'DD-MM-YYYY',
minDate: moment().add(2, 'days'),
});
<?php if (isset($end_date)) { ?>
$('#end_date').val('<?php echo @$end_date; ?>');
<?php } ?>
$("#start_date").on("dp.change", function (e) {
const[day, month, year] = $('#start_date').val().split("-");
var strt_dt = new Date(year + "-" + month + "-" + day);
var ultimate = strt_dt.setDate(strt_dt.getDate() + 1);
var d = new Date(ultimate);
$('#end_date').data("DateTimePicker").minDate(d);
});
$('#end_time').datetimepicker({
format: 'H:m',
});
$('#start_time').datetimepicker({
format: 'H:m',
});
});
$(document).on('change', '#start_date, #end_date', function () {
$('#end_date').attr('min', $('#start_date').val());
$('#start_date').attr('max', $('#end_date').val());
});
</script>
I am getting another problem only on Safari console which is : SyntaxError: Expected token ')'
And here is my following code:
<script>
function alertbox(heading = null, meassage = null) {
if (heading != null && meassage != null) {
$('#alert_heading').html(heading);
$('#alert_message').html(meassage);
$('#alert_model').modal('show');
}
}
</script>