I have view with two inputs where dates loading
Here is code in View of these inputs
<div class="device-selection">
<label for="startDate">@Dictionary.General.StartDate: </label>
<input id="startDate" class="round-input text-right" readonly />
</div>
<div class="device-selection">
<label for="endDate">@Dictionary.General.EndDate: </label>
<input id="endDate" class="round-input text-right" readonly />
</div>
In JS I have this code for showing calendar and populating inputs with dates:
$(document).ready(function () {
//cultureTwoLetterName is a global variable from the view that contains the two letter iso language name
$.datepicker.setDefaults($.datepicker.regional[cultureTwoLetterName]);
$('#calendar').weekMonthDatepicker({
changeMonth: true,
dateFormat: 'yy-mm-dd',
showWeek: true,
firstDay: 1,
weekHeader: '<span class="glyphicon glyphicon-arrow-down"></span>',
minDate: -loggingRetention,
maxDate: '+0D',
weekSelection: true,
weekSelected: SelectionCallback,
monthSelection: true,
monthSelected: SelectionCallback
});
$('#startDate').datepicker({
changeMonth: true,
dateFormat: 'yy-mm-dd',
firstDay: 1,
minDate: -loggingRetention,
maxDate: '+0D'
});
$('#endDate').datepicker({
changeMonth: true,
dateFormat: 'yy-mm-dd',
firstDay: 1,
minDate: -loggingRetention,
maxDate: '+0D'
});
$('#calendar').on('change', function () {
$('#startDate').val(moment($(this).val()).format('DD/MM/YYYY'));
$('#endDate').val(moment($(this).val()).format('DD/MM/YYYY'));
var start = $('#calendar').weekMonthDatepicker('getStartDate');
var stop = $('#calendar').weekMonthDatepicker('getEndDate');
var ui;
if (start != null && stop != null) {
ui = { 'startDate': start, 'endDate': stop };
}
PopulateTableDetails(null, ui);
});
$('#startDate').on('change', function () {
$(this).val(moment($(this).val()).format('DD/MM/YYYY'));
if ($('#endDate').val() == '' || moment($('#endDate').val(), 'DD/MM/YYYY') < moment($(this).val(), 'DD/MM/YYYY')) { //endDate niet ingevuld of < startDate --> endDate = startDate
$('#endDate').val($(this).val());
}
var start = moment($(this).val(), 'DD/MM/YYYY');
var stop = moment($('#endDate').val(), 'DD/MM/YYYY');
var ui = { 'startDate': start, 'endDate': stop };
PopulateTableDetails(null, ui);
});
$('#endDate').on('change', function () {
$(this).val(moment($(this).val()).format('DD/MM/YYYY'));
if ($('#startDate').val() == '' || moment($('#startDate').val(), 'DD/MM/YYYY') > moment($(this).val(), 'DD/MM/YYYY')) { //startDate niet ingevuld of > endDate --> startDate = endDate
$('#startDate').val($(this).val());
}
var start = moment($('#startDate').val(), 'DD/MM/YYYY');
var stop = moment($(this).val(), 'DD/MM/YYYY');
var ui = { 'startDate': start, 'endDate': stop };
});
});
I need to get values from startDate and endDate
So I try to write var startvalue = $('#startDate').val();
In this function $('#calendar').on('change', function () {
But I get empty alert with this code.
How I can get value of it correctly?
Thank's for help so much.