I have this code in my application using JQuery-UI datepicker:
$(function() {
$('.start_date').datepicker({
dateFormat: 'dd-mm-yy',
changeMonth: true,
changeYear: true,
showAnim: 'slideDown',
duration: 'fast',
minDate: +1,
yearRange: new Date().getFullYear() + ':' + new Date().getFullYear(),
});
$('.end_date').datepicker({
dateFormat: 'dd-mm-yy',
changeMonth: true,
changeYear: true,
showAnim: 'slideDown',
duration: 'fast',
minDate: +1,
yearRange: new Date().getFullYear() + ':' + new Date().getFullYear(),
enableOnReadonly: true,
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/ui-lightness/jquery-ui.css"/>
<input type="text" id="start_date" placeholder="Start Date" />
<input type="number" id="daysNumber" placeholder="Days" />
<input type="text" id="end_date" placeholder="End Date" readonly/>
I used this:
<script type="text/javascript">
$(document).ready(function () {
$( ".no_of_days" ).change(function() {
var periodval=$(".no_of_days").val();
var startDate = $('.start_date');
var endDate = $('.end_date');
//endDate.setDate(endDate.getDate() + periodval);
var dte = startDate.datepicker("getDate");
dte.setDate(dte.getDate()+periodval);
endDate.datepicker("setDate", dte);
});
$( '.start_date' ).datepicker({
dateFormat: 'dd-mm-yy',
changeMonth: true,
changeYear: true,
showAnim: 'slideDown',
duration: 'fast',
minDate: +1,
});
$( '.end_date' ).datepicker({
dateFormat: 'dd-mm-yy',
changeMonth: true,
changeYear: true,
showAnim: 'slideDown',
duration: 'fast',
minDate: +1,
yearRange: new Date().getFullYear() + ':' + new Date().getFullYear(),
enableOnReadonly: true,
});
});
</script>
but this error:
Uncaught TypeError: endDate.getDate is not a function
and this is highlighted:
endDate.setDate(endDate.getDate() + periodval);
I have seen some examples, but not really going for JQuery UI.
How do I
onchange daysNumber get end_date from start_date and Days (daysNumber)
and also on select start_date with the value of daysNumber get end_date
using JQuery-UI datepicker